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

ws-send! silently fails if the connection is closed #23

Open
lexi-lambda opened this issue Oct 9, 2024 · 1 comment
Open

ws-send! silently fails if the connection is closed #23

lexi-lambda opened this issue Oct 9, 2024 · 1 comment

Comments

@lexi-lambda
Copy link
Contributor

The following program runs without errors:

#lang racket/base

(require net/rfc6455
         net/url)

(define done-sem (make-semaphore))

(void
 (ws-serve
  #:port 8080
  (λ (conn req)
    (printf "received ~v\n" (ws-recv conn))
    (ws-close! conn)
    (ws-send! conn "should be closed")
    (printf "sent\n")
    (semaphore-post done-sem))))

(sleep 1)
(define conn (ws-connect (string->url "http://localhost:8080/")))
(ws-close! conn)
(semaphore-wait done-sem)

Note that the server-side ws-send! succeeds despite occurring immediately after a use of ws-close!. This seems unhelpful.

@lexi-lambda lexi-lambda changed the title ws-close! fails to close ports if the client has closed the connection ws-send! silently fails if the connection is closed Oct 9, 2024
@lexi-lambda
Copy link
Contributor Author

Actually looking at the source: this seems to be intended behavior. rfc6455-send! checks if the connection is closed, and if it is, it does nothing and returns. I find this quite unintuitive: I would expect an exception to be raised, as when writing to a closed output port. At the very least, it would be nice to document the behavior.

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