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

CPU use skyrockets and program bricks when connection closed by server #264

Open
Doinkboink opened this issue Aug 1, 2023 · 0 comments
Open

Comments

@Doinkboink
Copy link

I am connecting to a remote server by wrapping a TCP socket in a SSLContext object via the method provided in the readme. I am currently reading from the network with code that vaguely resembles the following:

@async begin
  try
    while true
      while (eof(mySSLContext)); end

      #read from mySSLContext and do other things
    end
  catch err
    #dump stack trace and exit()
  end
end

However, in certain scenarios, the server will close the connection for whatever reason. In response to this, my code ceases to respond to any input, including attempts to kill the process via Ctrl-C; I must enter task manager or kill the terminal completely to terminate the process. In the meantime, my code will begin consuming 15% of my CPU, up from an otherwise negligible amount.

Debug prints have shown that the problem seems to be caused by the eof(mySSLContext) somewhere, but I am having difficulty debugging into the package itself.

So far I have tried:
-Replacing 'eof(mySSLContext)' with 'eof(myTCPsocket)' ; however, this causes the code to block indefinitely on the eof check.
-Detecting eof or readability through other functions, such as 'isopen' or 'bytesavailable'. These do not seem to help.
-Notably, using the OpenSSL package for this exact purpose will throw an EOF error when the network stream closes; however, I tried and cannot find a way to get MbedTLS to trigger one of its error codes

Any help would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant