@@ -1180,6 +1180,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1180
1180
struct timeval timeout = {0 , 0 };
1181
1181
struct timeval * timeoutp = NULL ;
1182
1182
char * uniqid ;
1183
+ const char * persistent_id ;
1183
1184
phongo_char * errmsg = NULL ;
1184
1185
int errcode ;
1185
1186
char * dsn ;
@@ -1225,9 +1226,13 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1225
1226
1226
1227
spprintf (& uniqid , 0 , "%s:%d[%s]" , host -> host , host -> port , mongoc_uri_get_string (uri ));
1227
1228
1229
+ /* Do not persist SSL streams to avoid errors attempting to reinitialize SSL
1230
+ * on subsequent requests (see: PHPC-720) */
1231
+ persistent_id = mongoc_uri_get_ssl (uri ) ? NULL : uniqid ;
1232
+
1228
1233
MONGOC_DEBUG ("Connecting to '%s'" , uniqid );
1229
1234
zend_replace_error_handling (EH_SUPPRESS , NULL , & error_handling TSRMLS_CC );
1230
- stream = php_stream_xport_create (dsn , dsn_len , 0 , STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT , uniqid , timeoutp , (php_stream_context * )user_data , & errmsg , & errcode );
1235
+ 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 );
1231
1236
zend_restore_error_handling (& error_handling TSRMLS_CC );
1232
1237
1233
1238
if (!stream ) {
@@ -1247,7 +1252,7 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1247
1252
if (mongoc_uri_get_ssl (uri )) {
1248
1253
zend_replace_error_handling (EH_THROW , php_phongo_sslconnectionexception_ce , & error_handling TSRMLS_CC );
1249
1254
1250
- MONGOC_DEBUG ("Enabling SSL" );
1255
+ MONGOC_DEBUG ("Enabling SSL (stream will not be persisted) " );
1251
1256
1252
1257
/* Capture the server certificate so we can do further verification */
1253
1258
if (PHP_STREAM_CONTEXT (stream )) {
@@ -1261,22 +1266,22 @@ mongoc_stream_t* phongo_stream_initiator(const mongoc_uri_t *uri, const mongoc_h
1261
1266
php_stream_free (stream , PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR );
1262
1267
bson_set_error (error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_INVALID_TYPE , "Failed to setup crypto, is the OpenSSL extension loaded?" );
1263
1268
efree (dsn );
1264
- return NULL ;
1269
+ RETURN ( NULL ) ;
1265
1270
}
1266
1271
1267
1272
if (php_stream_xport_crypto_enable (stream , 1 TSRMLS_CC ) < 0 ) {
1268
1273
zend_restore_error_handling (& error_handling TSRMLS_CC );
1269
1274
php_stream_free (stream , PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR );
1270
1275
bson_set_error (error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_INVALID_TYPE , "Failed to setup crypto, is the server running with SSL?" );
1271
1276
efree (dsn );
1272
- return NULL ;
1277
+ RETURN ( NULL ) ;
1273
1278
}
1274
1279
1275
1280
if (!php_phongo_ssl_verify (stream , host -> host , error TSRMLS_CC )) {
1276
1281
zend_restore_error_handling (& error_handling TSRMLS_CC );
1277
1282
php_stream_pclose (stream );
1278
1283
efree (dsn );
1279
- return NULL ;
1284
+ RETURN ( NULL ) ;
1280
1285
}
1281
1286
1282
1287
zend_restore_error_handling (& error_handling TSRMLS_CC );
0 commit comments