@@ -1363,6 +1363,27 @@ static int s_websocket_connect(struct aws_mqtt_client_connection_311_impl *conne
1363
1363
return AWS_OP_ERR ;
1364
1364
}
1365
1365
1366
+ struct mqtt_on_websocket_setup_task_arg {
1367
+ struct aws_allocator * allocator ;
1368
+ struct aws_task task ;
1369
+ struct aws_mqtt_client_connection_311_impl * connection ;
1370
+ int error_code ;
1371
+ };
1372
+
1373
+ static void s_on_websocket_setup_task_fn (struct aws_task * task , void * userdata , enum aws_task_status status ) {
1374
+ (void )task ;
1375
+ (void )status ;
1376
+
1377
+ struct mqtt_on_websocket_setup_task_arg * on_websocket_setup_task_arg = userdata ;
1378
+ struct aws_mqtt_client_connection_311_impl * connection = on_websocket_setup_task_arg -> connection ;
1379
+ int error_code = on_websocket_setup_task_arg -> error_code ;
1380
+
1381
+ aws_mem_release (on_websocket_setup_task_arg -> allocator , on_websocket_setup_task_arg );
1382
+
1383
+ struct aws_websocket_on_connection_setup_data websocket_setup = {.error_code = error_code };
1384
+ s_on_websocket_setup (& websocket_setup , connection );
1385
+ }
1386
+
1366
1387
static void s_websocket_handshake_transform_complete (
1367
1388
struct aws_http_message * handshake_request ,
1368
1389
int error_code ,
@@ -1417,9 +1438,21 @@ static void s_websocket_handshake_transform_complete(
1417
1438
return ;
1418
1439
1419
1440
error :;
1420
- /* Proceed to next step, telling it that we failed. */
1421
- struct aws_websocket_on_connection_setup_data websocket_setup = {.error_code = error_code };
1422
- s_on_websocket_setup (& websocket_setup , connection );
1441
+ /* Proceed to next step, telling it that we failed.
1442
+ * s_on_websocket_setup will shutdown MQTT connection, and this MUST happen on the MQTT connection's event loop. */
1443
+ struct mqtt_on_websocket_setup_task_arg * on_websocket_setup_task_arg =
1444
+ aws_mem_calloc (connection -> allocator , 1 , sizeof (struct mqtt_on_websocket_setup_task_arg ));
1445
+ on_websocket_setup_task_arg -> allocator = connection -> allocator ;
1446
+ /* NOTE: No need in acquiring MQTT connection ref counter, as it is already acquired at the start of connection
1447
+ * process. s_on_websocket_setup will release it. */
1448
+ on_websocket_setup_task_arg -> connection = connection ;
1449
+ on_websocket_setup_task_arg -> error_code = error_code ;
1450
+ aws_task_init (
1451
+ & on_websocket_setup_task_arg -> task ,
1452
+ s_on_websocket_setup_task_fn ,
1453
+ (void * )on_websocket_setup_task_arg ,
1454
+ "on_websocket_setup_task" );
1455
+ aws_event_loop_schedule_task_now (connection -> loop , & on_websocket_setup_task_arg -> task );
1423
1456
}
1424
1457
1425
1458
/*******************************************************************************
0 commit comments