Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attach_socket_import tests hang waiting for "process" event #1552

Closed
int19h opened this issue Jul 1, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@int19h
Copy link
Contributor

commented Jul 1, 2019

(https://github.com/microsoft/ptvsd/tree/dbg_adapter_refactor)

When running multiple tests with start_method set to attach_socket_cmdline or attach_socket_import, subsequent tests fail because they cannot reuse the port number. It looks like ptvsd is not getting shut down properly, or the next test starts running before ptvsd exits.

Estimate is uncertain, because this needs to be investigated to determine the root cause.

Only happens on Python 2.7.

@int19h int19h added the Test-issue label Jul 1, 2019

@int19h int19h self-assigned this Jul 1, 2019

@karthiknadig karthiknadig added this to the Jun 2019.2 milestone Jul 2, 2019

@int19h

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

I misindentified the root cause. This is actually a consistent issue in all tests that use start_method="attach_socket_import". For some as yet unclear reason, this gets ptvsd into such a condition whence the "process" DAP event never gets reported. And the implementation of debug.Session expects that event in handshake().

Thus, the test hangs, and eventually times out. But debuggee process is still out there, and it still has the debug server in it listening on a port. Thus, the next test that does any form of "attach_socket" will fail because the port it needs is hogged.

The problem itself is specific to "attach_socket_import", though - "attach_socket_cmdline" works fine by itself. The only reason why cmdline was failing is because of the port being in use.

@int19h int19h changed the title ptvsd port does not get properly closed when running attach_socket tests attach_socket_import tests hang waiting for "process" event Jul 2, 2019

@fabioz

This comment has been minimized.

Copy link
Collaborator

commented Jul 2, 2019

As a note, on pydevd I use a new port for each new test... Seeing the way that the port is gotten on ptvsd tests (get_unique_port in helpers.py), I think it's possible that the port being gotten from the PYTEST_XDIST_WORKER could be a port we can't really use (and it could be making tests fail).

As a reference, the way that pydevd gets new ports is in: pydev_localhost.py - get_socket_name.

@int19h

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

The port logic itself shouldn't result in any clashes, because every worker uses its own distinct port, and every worker runs tests sequentially on that port.

This bears out in practice - DebugSession can connect to ptvsd, and starts talking to it. It also starts talking to pydevd, and e.g. successfully sets protocol to JSON. It breaks down sometime after, once it gets to handling "attach".

int19h added a commit to int19h/ptvsd that referenced this issue Jul 3, 2019

Fix microsoft#1552: attach_socket_import tests hang waiting for "proc…
…ess" event

Preload codecs used by ptvsd and pydevd to avoid deadlocks when calling wait_for_attach()  while importing a module on Python 2.

int19h added a commit to int19h/ptvsd that referenced this issue Jul 3, 2019

Fix microsoft#1552: attach_socket_import tests hang waiting for "proc…
…ess" event

Preload codecs used by ptvsd and pydevd to avoid deadlocks when calling wait_for_attach()  while importing a module on Python 2.

int19h added a commit that referenced this issue Jul 3, 2019

Fix #1552: attach_socket_import tests hang waiting for "process" event
Preload codecs used by ptvsd and pydevd to avoid deadlocks when calling wait_for_attach()  while importing a module on Python 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.