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

Fix: ResourceWarning unclosed socket #690

Merged
merged 1 commit into from
May 15, 2021

Conversation

rmkraeuchi
Copy link
Contributor

Close socket if error occurs in open_socket. This can happen if websocket is not available.

Current Code:

url = 'ws://10.1.1.11:8081/ws'   # any unreachable url is working
ws = websocket.WebSocket()
ws.connect(url=url, timeout=0.1)

Received warning in console:
ResourceWarning: unclosed <socket.socket fd=636, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('0.0.0.0', 56100), raddr=('10.1.1.11', 8081)>

Close socket if error occurs during opening socket
@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #690 (f844681) into master (afd8a77) will increase coverage by 0.11%.
The diff coverage is 50.00%.

❗ Current head f844681 differs from pull request most recent head 2179eea. Consider uploading reports for the commit 2179eea to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #690      +/-   ##
==========================================
+ Coverage   74.72%   74.84%   +0.11%     
==========================================
  Files          13       13              
  Lines        1286     1288       +2     
  Branches      250      251       +1     
==========================================
+ Hits          961      964       +3     
+ Misses        211      209       -2     
- Partials      114      115       +1     
Impacted Files Coverage Δ
websocket/_http.py 70.53% <50.00%> (-0.21%) ⬇️
websocket/_handshake.py 73.91% <0.00%> (-1.74%) ⬇️
websocket/_core.py 78.00% <0.00%> (+1.00%) ⬆️
websocket/_utils.py 88.88% <0.00%> (+5.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afd8a77...2179eea. Read the comment docs.

@engn33r engn33r merged commit ab1ebf7 into websocket-client:master May 15, 2021
@engn33r
Copy link
Collaborator

engn33r commented May 15, 2021

Thanks for the PR. Good catch, although I was not able to recreate the error message you received. I haven't checked if there are other places in this project where resources are not cleanly handled in error or exception cases.

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

Successfully merging this pull request may close these issues.

None yet

2 participants