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

_sockindex left with non-default value when connection fails #256

Open
nschurando opened this issue Apr 3, 2024 · 0 comments · May be fixed by #176
Open

_sockindex left with non-default value when connection fails #256

nschurando opened this issue Apr 3, 2024 · 0 comments · May be fixed by #176
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@nschurando
Copy link

I believe I have found an issue. I raised it in the form of PR #176 two years ago, but it received little attention, so I'm opening a proper issue here.

When a connection established through EthernetClient::connect fails, the stat variable will have a value of SnSR::CLOSED causing the function to return immediately with a value of 0 without resetting the _sockindex variable to the default MAX_SOCK_NUM.

The problem manifests itself at least when the following chain of events happen:

  1. Object A holds an instance of EthernetClient. It tries to establish a TCP connection trough EthernetClient::connect which fails because the port is not open on the server. Its instance is left with _sockindex at 0.

  2. Object B performs a UDP exchange (EthernetUDP::begin, EthernetUDP::beginPacket, EthernetUDP::write, EthernetUDP::endPacket, EthernetUDP::parsePacket, read but no EthernetUDP::stop yet). It is attributed _sockindex of 0.

  3. Object A tries again to connect, his instance still has a _sockindex of 0, which leads to chaos because it's referencing a completely different socket.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants