Skip to content

Allow multithread write#81

Open
fukamachi wants to merge 7 commits into
masterfrom
allow-multithread-write
Open

Allow multithread write#81
fukamachi wants to merge 7 commits into
masterfrom
allow-multithread-write

Conversation

@fukamachi

Copy link
Copy Markdown
Owner

No description provided.

@fukamachi

Copy link
Copy Markdown
Owner Author

ref fukamachi/websocket-driver#35

@ghost

ghost commented Aug 9, 2019

Copy link
Copy Markdown

Ah thank you for bringing this up yourself! I recently wrote a short tutorial about websocket use in CL, and I had wanted to used Clack + Woo + websocket-driver , but hit this issue, and so switched to Hunchentoot+Hunchensocket instead.

@shakatoday

shakatoday commented Aug 4, 2022

Copy link
Copy Markdown

CLOG also needs this. I hope my mentioning can help Woo get more momentum from the whole Common Lisp community. Thanks!

@fukamachi

Copy link
Copy Markdown
Owner Author

Oh, thanks!
I don't remember why this PR is frozen. I'll make it revived.

@rabbibotton

Copy link
Copy Markdown

Was this ever resolved?

@aurelien-slodzian

Copy link
Copy Markdown

It does not seem resolved as of today, at least not in the Quicklisp distribution.

This minimalist connection handler works perfectly:

(defun handle-connection-nt (env)
  "When a new connection is requested for a client, create or reuse an existing channel"
  (let* ((ws (wsd:make-server env)))
    (wsd:on :message ws
            (lambda (msg)
              (wsd:send-text ws (reverse msg))))
    (lambda (responder)
      (declare (ignore responder))
      (wsd:start-connection ws))))

However, if I put the message handler in a thread, then woo closes the connection before the answer is sent. Hutchentoot works fine, so I switched to it (momentarily I hope)

 (defun handle-connection (env)
  (let* ((ws (wsd:make-server env)))
    (self *ws* ws)
    (wsd:on :message ws
            (lambda (msg)
              (bt2:make-thread #'(lambda () (wsd:send-text ws (reverse msg))))))
    (lambda (responder)
      (declare (ignore responder))
      (wsd:start-connection ws))))

When I run this with (clack:clackup #'handle-connection :server :woo :port 4000) and connect from a client, then server does not answer to messages and if I check the connection's state:

(wsd:ready-state *ws*)
:CLOSED

Of course, my application uses threads for more serious reasons than raising issues with woo. But at least, this code may be used as a test for when the bug will be solved (hopefully soon ?).

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.

4 participants