@@ -1133,6 +1133,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1133
1133
struct timeval timeout = {0 , 0 };
1134
1134
struct timeval * timeoutp = NULL ;
1135
1135
char * uniqid ;
1136
+ const char * persistent_id ;
1136
1137
phongo_char * errmsg = NULL ;
1137
1138
int errcode ;
1138
1139
char * dsn ;
@@ -1178,9 +1179,13 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1178
1179
1179
1180
spprintf (& uniqid , 0 , "%s:%d[%s]" , host -> host , host -> port , mongoc_uri_get_string (uri ));
1180
1181
1182
+ /* Do not persist SSL streams to avoid errors attempting to reinitialize SSL
1183
+ * on subsequent requests (see: PHPC-720) */
1184
+ persistent_id = mongoc_uri_get_ssl (uri ) ? NULL : uniqid ;
1185
+
1181
1186
MONGOC_DEBUG ("Connecting to '%s'" , uniqid );
1182
1187
zend_replace_error_handling (EH_SUPPRESS , NULL , & error_handling TSRMLS_CC );
1183
- stream = php_stream_xport_create (dsn , dsn_len , 0 , STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT , uniqid , timeoutp , (php_stream_context * )user_data , & errmsg , & errcode );
1188
+ stream = php_stream_xport_create (dsn , dsn_len , 0 , STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT , persistent_id , timeoutp , (php_stream_context * )user_data , & errmsg , & errcode );
1184
1189
zend_restore_error_handling (& error_handling TSRMLS_CC );
1185
1190
1186
1191
if (!stream ) {
@@ -1200,7 +1205,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1200
1205
if (mongoc_uri_get_ssl (uri )) {
1201
1206
zend_replace_error_handling (EH_THROW , php_phongo_sslconnectionexception_ce , & error_handling TSRMLS_CC );
1202
1207
1203
- MONGOC_DEBUG ("Enabling SSL" );
1208
+ MONGOC_DEBUG ("Enabling SSL (stream will not be persisted) " );
1204
1209
1205
1210
/* Capture the server certificate so we can do further verification */
1206
1211
if (PHP_STREAM_CONTEXT (stream )) {
@@ -1214,22 +1219,22 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1214
1219
php_stream_free (stream , PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR );
1215
1220
bson_set_error (error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_INVALID_TYPE , "Failed to setup crypto, is the OpenSSL extension loaded?" );
1216
1221
efree (dsn );
1217
- return NULL ;
1222
+ RETURN ( NULL ) ;
1218
1223
}
1219
1224
1220
1225
if (php_stream_xport_crypto_enable (stream , 1 TSRMLS_CC ) < 0 ) {
1221
1226
zend_restore_error_handling (& error_handling TSRMLS_CC );
1222
1227
php_stream_free (stream , PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR );
1223
1228
bson_set_error (error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_INVALID_TYPE , "Failed to setup crypto, is the server running with SSL?" );
1224
1229
efree (dsn );
1225
- return NULL ;
1230
+ RETURN ( NULL ) ;
1226
1231
}
1227
1232
1228
1233
if (!php_phongo_ssl_verify (stream , host -> host , error TSRMLS_CC )) {
1229
1234
zend_restore_error_handling (& error_handling TSRMLS_CC );
1230
1235
php_stream_pclose (stream );
1231
1236
efree (dsn );
1232
- return NULL ;
1237
+ RETURN ( NULL ) ;
1233
1238
}
1234
1239
1235
1240
zend_restore_error_handling (& error_handling TSRMLS_CC );
0 commit comments