Skip to content

Commit f8f13fa

Browse files
fix: close makefile wrapper in Python force_stop() to trigger TCP disconnect
Python's socket.makefile() holds its own reference to the socket. Calling socket.close() alone won't release the OS-level resource until the makefile wrapper is also closed. This meant force_stop() wasn't actually closing the TCP connection, so the server never detected the disconnect and never sent capabilities.changed events to other clients. Fix: close the file wrapper before the socket in SocketWrapper.terminate(). Unskip test_capabilities_changed_when_elicitation_provider_disconnects.
1 parent 9f69e53 commit f8f13fa

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

python/copilot/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,13 @@ def __init__(self, sock_file, sock_obj):
22592259
self._socket = sock_obj
22602260

22612261
def terminate(self):
2262+
# Close the file wrapper first — makefile() holds its own
2263+
# reference to the socket, so socket.close() alone won't
2264+
# release the OS-level resource until the wrapper is closed too.
2265+
try:
2266+
self.stdin.close()
2267+
except OSError:
2268+
pass
22622269
try:
22632270
self._socket.close()
22642271
except OSError:

python/e2e/test_ui_elicitation_multi_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ async def handler(
225225

226226
await session2.disconnect()
227227

228-
@pytest.mark.skip(
229-
reason="Python force_stop() doesn't trigger server-side capabilities.changed "
230-
"reliably in the replay proxy. The equivalent .NET test passes. "
231-
"Tracked for follow-up."
232-
)
233228
async def test_capabilities_changed_when_elicitation_provider_disconnects(
234229
self, mctx: ElicitationMultiClientContext
235230
):

0 commit comments

Comments
 (0)