Opened 5 years ago

Last modified 5 years ago

#13193 new Bugs

multiple sockets (reuse_address) + multiple io_service = packages never received

Reported by: rafal2@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.63.0 Severity: Problem
Keywords: reuse_address, io_service, multiple Cc:

Description

In example program, we open several UDP sockets (each on same address/port - with reuse_address), and they use several io_service.

The result is that async_receive_from never reads any data.

1) N sockets (same addr/port), using N various io_service - doe not work 2) N sockets (each own port), using N various io_service - works 3) N sockets (same addr/port), but using same 1 io_service - works 4) 1 socket - works

The full test case is in github:

https://github.com/rfree-d/cppfuns/tree/79093a5458867ddbf0d36f0170a78465194370a4/asio_udp_srv

if you run "make run" then program starts using "mport" option - each socket gets own port (so no need for the reuse flag) - and program works fine.

if you run "make run_bug" then it is started without the "mport" and all sockets listen on port 9000 - and then the program does not work

if you run the binary with no options then it shows usage (or grep sources for 'options').

You can test program by sending data to UDP 9000 localhost, or just build test program in other directory up:

https://github.com/rfree-d/cppfuns/tree/79093a5458867ddbf0d36f0170a78465194370a4/asio_udp_cli

there "make", and run it with options like "127.0.0.1 9000" it is interactive, to send many data use:

aaa 1000 100000

for big packet sent once use

aaa 1000 1

to send one packet with string "exit" use

exit 1 1

Tested on Linux Debian 8 and 9.

Change History (1)

comment:1 by anonymous, 5 years ago

Formatting fix:

1) N sockets (same addr/port), using N various io_service - does not work

2) N sockets (each own port), using N various io_service - works

3) N sockets (same addr/port), but using same 1 io_service - works

4) 1 socket - works

For clarity:

this program is supposed to receive UDP data (and throw it away, performance test) using multiple threads/buffers, and optionally multiple sockets and/or io_service.

When we turn all of this on, many sockets and threads and io_services, if they use same addres+port (via reuse addr) then program shows receive speed 0 and count 0. (except for spurious receiving 1 packet from time to time, not sure what this possible bug is about).

If we either use different ports so the reuse-port is not needed (by adding command line option "mport" at end as in Makefile make run), or if we use just 1 io_service, then when we send the data (e.g. from the sibling test program linked above) then all works (e.g. 100 MB/sec and more).

p.s. you can enable/disable some debug by toggling the "#if 0" at very top of program.

Note: See TracTickets for help on using tickets.