g_cancellable_connect() doesn't work like its docs claim, has race condition
@danw
Submitted by Dan Winship Link to original bug (#711286)
Description
The g_cancellable_connect() docs claim:
- @callback is called at most once, either directly at the
- time of the connect if @cancellable is already cancelled,
- or when @cancellable is cancelled in some thread.
but the "at most once" is only true if you throw the cancellable away after it fires. If you use the cancellable multiple times, then @callback will be called every time @cancellable is cancelled, UNLESS it was already cancelled when you called g_cancellable_connect(), in which case it it will only be called once.
Dropping the "at most once" rule and changing the already-cancelled case to connect to the signal anyway seems likely to break people, so the remaining options are (1) make the not-already-cancelled case also obey the "at most once" rule, by disconnecting from the signal handler after the first time it's emitted, or (2) document the inconsistency.
Either way, GCancellableSource is broken and needs to revert back to using g_signal_connect() for compatibility with its old behavior, qv bug 710691 comment 12.