Bug: disconnectedEvent fires twice per disconnect
Version
ib_async 2.1.0
Description
Every disconnect causes disconnectedEvent to fire twice because it is wired from two independent sources:
IB.__init__ connects client.apiEnd to disconnectedEvent (so when the client layer detects disconnect, the event fires)
IB.disconnect() explicitly calls self.disconnectedEvent.emit() after calling self.client.disconnect()
When IB.disconnect() is called, the client disconnect triggers apiEnd (which fires disconnectedEvent via the wiring in #1), and then IB.disconnect() fires it again directly (#2).
Impact
Any handler registered on disconnectedEvent executes twice per disconnect. This can cause issues with cleanup logic, reconnection state machines, and logging that assumes a 1:1 relationship between disconnects and events.
Steps to reproduce
from ib_async import IB
ib = IB()
count = 0
def on_disconnect():
global count
count += 1
print(f"disconnectedEvent fired (count={count})")
ib.disconnectedEvent += on_disconnect
await ib.connectAsync('127.0.0.1', 4002, clientId=1)
ib.disconnect()
print(f"Total fires: {count}") # Prints 2, expected 1
Expected behavior
disconnectedEvent should fire exactly once per disconnect, regardless of whether the disconnect was initiated by IB.disconnect() or by a connection drop.
Suggested fix
Either remove the explicit self.disconnectedEvent.emit() from IB.disconnect() (relying on the apiEnd wiring), or guard the explicit emit with a flag to prevent double-firing.
Bug:
disconnectedEventfires twice per disconnectVersion
ib_async 2.1.0
Description
Every disconnect causes
disconnectedEventto fire twice because it is wired from two independent sources:IB.__init__connectsclient.apiEndtodisconnectedEvent(so when the client layer detects disconnect, the event fires)IB.disconnect()explicitly callsself.disconnectedEvent.emit()after callingself.client.disconnect()When
IB.disconnect()is called, the client disconnect triggersapiEnd(which firesdisconnectedEventvia the wiring in #1), and thenIB.disconnect()fires it again directly (#2).Impact
Any handler registered on
disconnectedEventexecutes twice per disconnect. This can cause issues with cleanup logic, reconnection state machines, and logging that assumes a 1:1 relationship between disconnects and events.Steps to reproduce
Expected behavior
disconnectedEventshould fire exactly once per disconnect, regardless of whether the disconnect was initiated byIB.disconnect()or by a connection drop.Suggested fix
Either remove the explicit
self.disconnectedEvent.emit()fromIB.disconnect()(relying on theapiEndwiring), or guard the explicit emit with a flag to prevent double-firing.