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

net: tcp: Context still open after timeout on connect #44504

Closed
ssharks opened this issue Apr 4, 2022 · 5 comments
Closed

net: tcp: Context still open after timeout on connect #44504

ssharks opened this issue Apr 4, 2022 · 5 comments
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@ssharks
Copy link
Collaborator

ssharks commented Apr 4, 2022

Describe the bug
When a TCP connect fails with a timeout, because there is no communication possible, the context is not cleaned up properly.

To Reproduce
Use the testcase as submitted in the pull request
#44501

Run the test using
./scripts/twister -T tests/net/socket/tcp -p qemu_x86

Expected behavior
When a socket connect timeouts, I would expect the context to close, no connection has been build, so why do we need to close it?

Impact
Could cause resource leakage in case of a bad network connection.

Environment:

@ssharks ssharks added the bug The issue is a bug, or the PR is fixing a bug label Apr 4, 2022
@mbolivar-nordic mbolivar-nordic added the priority: medium Medium impact/importance bug label Apr 5, 2022
@rlubos
Copy link
Contributor

rlubos commented Apr 12, 2022

Hi @ssharks. I can't reproduce the issue you describe. The test case you provide indeed fail, but the reason for this is not that net_context leaks somehow on connect() timeout, but because you don't close the server socket. When both, client and server sockets are closed after the failed connection attempt, there is no context left open.

@ssharks
Copy link
Collaborator Author

ssharks commented Apr 12, 2022

So if I understand you correctly, a socket should be closed even when the connect fails?

@rlubos
Copy link
Contributor

rlubos commented Apr 13, 2022

So if I understand you correctly, a socket should be closed even when the connect fails?

That's right, once opened the only way to clean up its resources is to close it. Anyway, it's generally expected that you always close a socket that is no longer used, it's not only about net_context but also the file description needs to be freed etc.

@ssharks
Copy link
Collaborator Author

ssharks commented Apr 14, 2022

The suggested changes have been implemented in the pull request and now the tests pass. So there is no issue in the stack on this point.

@ssharks ssharks closed this as completed Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

5 participants
@henrikbrixandersen @ssharks @rlubos @mbolivar-nordic and others