mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
gio/tests: Prevent hangs and aborts in socket-listener
Fix two problems: 1) If g_socket_service_stop is called before the accept call is requeued, then the reference count won't decrease and this code will hang forever: while (G_OBJECT (service)->ref_count == ref_count) g_main_context_iteration (NULL, TRUE); 2) Sometimes the testcase fails (maybe 1 in 200 times for me): GLib-GIO:ERROR:socket-listener.c:73:connection_cb: assertion failed (G_OBJECT (service)->ref_count == 2): (3 == 2) Aborted (core dumped) The problem is that depending on ordering, cancellation of the async listener can require further main context iterations before it releases the reference on the socket service. Furthermore, in some cases, it requires at least one iteration. https://bugzilla.gnome.org/show_bug.cgi?id=712570
This commit is contained in:
parent
53abf0dc7d
commit
7d9816934e
@ -99,7 +99,6 @@ test_threaded_712570 (void)
|
||||
GMainLoop *loop;
|
||||
GSocketClient *client;
|
||||
GError *error = NULL;
|
||||
int ref_count;
|
||||
|
||||
g_test_bug ("712570");
|
||||
|
||||
@ -135,11 +134,13 @@ test_threaded_712570 (void)
|
||||
|
||||
/* Stop the service and then wait for it to asynchronously cancel
|
||||
* its outstanding accept() call (and drop the associated ref).
|
||||
* At least one main context iteration is required in some circumstances
|
||||
* to ensure that the cancellation actually happens.
|
||||
*/
|
||||
ref_count = G_OBJECT (service)->ref_count;
|
||||
g_socket_service_stop (G_SOCKET_SERVICE (service));
|
||||
while (G_OBJECT (service)->ref_count == ref_count)
|
||||
do
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
while (G_OBJECT (service)->ref_count > 3);
|
||||
|
||||
/* Drop our ref, then unlock the mutex and wait for the service to be
|
||||
* finalized. (Without the fix for 712570 it would hang forever here.)
|
||||
|
Loading…
Reference in New Issue
Block a user