[racket] distributed place messages: "write" isn't atomic
At Fri, 20 Mar 2015 10:14:12 +0000, Tim Brown wrote:
> I have written a remote-server (as in
> racket/place/define-remote-server), which I am then trying to use from a
> web-server. The remote-server is running on a remote node (which is, in
> fact, localhost).
>
> [...]
>
> It seems that the RPC packets are overlapping. [...] the write to the
> remote host is non-atomic, and not synchronised.
That sounds likely.
> Has anyone else done this/encountered this?
I doubt that anyone else has tried something similar.
> Will a write of a single string suffer this?
Yes, I think it will still be a problem for any message that is large
enough.
> Would a semaphore (or similar) around sconn-write-flush be the right
> place/time for synchronising messages.
That sounds right to me. Specifically, it looks like putting the lock
in the `socket-connection%` object and using it in `_write-flush` would
be the right place. Let me know if that solves the problem, and if so,
I'll apply that patch.
> Also -- I notice that write-flush is defined as:
>
> (define (write-flush msg [p (current-output-port)])
> (flush-output)
> (write msg p)
> (flush-output p))
>
> Should that first flush-output be on p?
Probably, but... Unless always flushing the current output port was
intended (which doesn't sound like a good idea), I don't see how that
first `(flush-output)` can be useful. Probably the right change is to
just remove it.