From: mockturtle on
Dear all,
I would like to share with you a problem we recently experienced with
Create_Selector on Windows and that drove us (especially my student)
crazy. Maybe some of you could be interested in it.

My student is developing a program in Ada (did you guess? :) that
communicates over the network. The code includes a procedure like

procedure read_with_timeout
(socket : socket_type;
result : out data_packet;
timeout : duration) is
selector : selector_type;
-- other variables
begin
create_selector(selector);
-- Other code that adds socket to the read
-- set and waits for data or timeout
close_selector(selector);
end read_with_timeout;

The procedure above is called inside a loop. If the read operation
was succesfull, the packet is processed, otherwise the code does
something else.

On Linux everything is fine and the code runs without any problem. On
Windows the code runs for approximately 2 minutes then it dies with
"10055 No buffer space available".

My student fought with this problem for a couple of days, then he
decided to give a look to the TCP/IP traffic and he discovered that
there were many (hundreds?) TCP connection to localhost in TIME-WAIT
state. He got the intuition that the problem could be on the select
and he moved the definition and initialization of Selector outside the
procedure, in the package body. This solved the problem, so we
deduced that the TCP connections were opened by the Create_Selector.
However, the song "Perché lo fai?" (Why do you do it?) by Marco Masini
came irresistibly to our minds...

By looking into the GNAT sources I discovered the reason (correct me
if I am wrong): in order to allow for the "abort" of check_selector,
GNAT create two connected file descriptor and add the read-side to
the list of descriptors waited for. On Linux the two FDs are created
with pipe() and no problem arise, but on Windows it falls back to a
portable version that uses TCP connections. Those connections remain
in the TIME-WAIT state and consume resources. Note that
Close_Selector was called at the end of the procedure (actually, the
TIME-WAIT state is a symptom that the connection was closed).

As I said above, we were able to make the code work with the slightly
inelegant (but innocuous [in our specific case]) solution of moving
the selector outside the procedure. However I decided to signal this
issue because it could be of some help to someone else (and maybe it
could be read by someone of the GNAT people).

From: Pascal Obry on
Le 05/12/2009 10:22, mockturtle a �crit :
> Dear all,
> I would like to share with you a problem we recently experienced with
> Create_Selector on Windows and that drove us (especially my student)
> crazy. Maybe some of you could be interested in it.

I think this is worth reporting to AdaCore.

--

--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.net - http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B