Code Monkey home page Code Monkey logo

Comments (13)

marksamman avatar marksamman commented on May 17, 2024

Update: I just noticed that the application didn't actually crash, everything still works fine, but I still think this should be handled by the websockets module so it doesn't print "socket.send() raised exception"/stack traces if a client has disconnected (or perhaps pass along the exceptions so they can be handled by applications using the module).

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

handleConnection should probably end with:

try:
    yield from websocket.recv()
finally:
    wsClients[link_id].remove(websocket)

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

I'm confident that this commit should fix your problem. Let me know if it doesn't work.

from websockets.

marksamman avatar marksamman commented on May 17, 2024

Thanks! I've upgraded to version 2.1, and it doesn't print any tracebacks anymore but it still prints:
"socket.send() raised exception.".

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

Errors should not pass silently -- PEP 20

;-)

from websockets.

marksamman avatar marksamman commented on May 17, 2024

I don't disagree with that, but the problem is that the module (asyncio in this case I believe) is logging the error instead of passing along whatever exception that was raised in socket.send(). This way it can't be handled by the consumer of the API/module ("socket.send() raised exception." isn't very descriptive either), so that message is just trashing the logs when in my use case it should just be ignored because it just means that the client has disconnected before/while calling send().

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

I'll have a second look at this issue.

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

asyncio logs this message after 5 attemps to write to a closed socket.

If it's just a race condition when your system is dying under load, there isn't much to fix.

But if it's websockets trying to write data to the connection after the socket dies, then I can do something.

from websockets.

marksamman avatar marksamman commented on May 17, 2024

It is websockets trying to write to the connection after the remote connection has disconnected (but websockets hasn't context switched enough to fail the yield from recv before the 5 attempts to send). I have only reproduced it under heavy load (running apachebench on the same machine), so feel free to close it if you feel that this isn't a real issue because it only happens under heavy load. It's not very important to me either way, I just thought I'd report it because I didn't expect this behavior.

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

Would you mind testing pull request #27 and report if it fixes your problem?

I'm sorry, I haven't replicated your setup yet, so there's a bit of trial and error going on.

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

This pull request is expected to make yield from client.send(json_data) raise an exception when the socket died, which should allow you to deal with the error as you wish in
https://github.com/marksamman/pylinkshortener/blob/master/app/websocket/__init__.py#L48.

from websockets.

marksamman avatar marksamman commented on May 17, 2024

I have confirmed that the pull request fixes my issue. Thanks!

from websockets.

aaugustin avatar aaugustin commented on May 17, 2024

Well thanks a lot for reporting it and persisting until I fixed it ;-)

Let me know if there's anything else I can help with.

from websockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.