[Cuis-dev] Cuis-dev Digest, Vol 67, Issue 44

Martin McClure martin at hand2mouse.com
Tue Oct 29 10:54:03 PDT 2024


Hi,

A good question, and a very good point.

Yes, what /should/ be done is to listenOn: 0, and then /use that 
socket/, not close it and then try to open another one on the same port 
number. Definitely a race condition; that port number could be grabbed 
by someone else in the intervening time.

Regards,

-Martin

On 10/29/24 10:40, r. clayton via Cuis-dev wrote:
>    openPort
>        "Answer an open port number"
>        | port socket |
>
>        socket := Socket newTCP.
>        socket listenOn: 0. "gets an ephemeral port"
>        port := socket localPort.
>        socket close.
>        ^port.
>
> Forgive me for asking a possibly dumb question, but how is this not a race condition waiting to happen?  Ports are a system-wide resource (considering ports above 1023).  What prevents a process elsewhere on the system, not necessarily within Cuis, from allocating the port returned by openPort?
>
> Also, since I'm being picky, "open" is probably not the best choice of words if I'm correctly understanding the code's intention.  Despite being in the vernacular, "open" doesn't doesn't necessarily mean "available" or "unallocated."  You could argue that "open" means "unavailable" and "allocated" (consider TCP to make this argument clear).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20241029/419d3374/attachment.htm>


More information about the Cuis-dev mailing list