Skip to content

Is there a way to pass down to the application that the client disconnected? #308

@viktordick

Description

@viktordick

We recently switched from using Zope 2 to Zope 4, now using waitress as web server and have tried to look into how to re-implement a patch that we had implemented in Zope 2 before.

The idea is that end users that are impatient and reload a page that takes too long to load or close the page often make the problem worse by putting more strain on the server. The first request is still being processed even though there is no one out there that is still expecting the result. Our solution was to put a signal into the request object and some strategic places inside the application server checked for the signal, aborting if it was found (after all, it is not possible to kill threads).

Is there a way to accomplish something similar with waitress? I am not sure if this goes against the whole spirit of the WSGI approach, but maybe it is possible to change the environment after the fact and check for it inside the application? Or maybe even allow an application to insert a callable into the environment and call it when the client disconnects?

I am not even sure how to detect this situation in the approach that waitress is using. In principle, if a client disconnects, the socket becomes readable but returns a zero-length byte string when recv is called. However, once a request is completely transferred and the task is created, the corresponding socket seems to no longer be in the list of sockets that are checked for readability in the 'select' loop.

I thought I'd ask here because others might face the same problem and maybe the community is interested in creating a solution for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions