[Bug 231848] accept4() doesn't return a socket address when threading is involved

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

            Bug ID: 231848
           Summary: accept4() doesn't return a socket address when
                    threading is involved
           Product: Base System
           Version: 11.2-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: threads
          Assignee: [hidden email]
          Reporter: [hidden email]

We've added threading support to socket_wrapper [1] which is a tool to create
artificial networks for testing.

We wrote several tests to make sure socket_wrapper works correctly. However
there are two tests which fail on FreeBSD but work correctly on Linux.

When running with socket_wrapper we tracked it down to accept4() not filling
out the passed sockaddr. socket_wrapper uses unix socket and we would expect
the unix socket path returned by accept4, which isn't the case.

If I change the echo_srv to write to a file and enable debugging of
socket_wapper this slows down the whole thing and the tests pass correclty.
This means accept4 correctly filling out the sockaddr structure. So this looks
like a race condition in the freebsd libc code.

You can find the code we are currently working on at [2].

git clone https://git.cryptomilk.org/users/asn/socket_wrapper.git
cd socket_wrapper
mkdir obj
cd obj
cmake -DCMAKE_BUILD_TYPE=Debug -DUINIT_TESTING=ON ..
make -j8

To run the whole test suite, you can use:
ctest --output-on-failure

Which should result in:

The following tests FAILED:
         20 - test_thread_echo_tcp_connect (Failed)
         21 - test_thread_echo_tcp_write_read (Failed)
         22 - test_thread_echo_tcp_sendmsg_recvmsg (Failed)

To run an individual test you can use:

ctest -V -R test_thread_echo_tcp_write_read


This will also print you how it is called, normally this is something like:

CMOCKA_TEST_ABORT=1 \
LD_PRELOAD=/home/vagrant/workspace/projects/socket_wrapper/obj/src/libsocket_wrapper.so
\
tests/test_thread_echo_tcp_write_read


The test could also be run without socket_wrapper using real sockets:

CMOCKA_TEST_ABORT=1 \
TORTURE_SERVER_ADDRESS_IPV4="127.0.0.1" \
TORTURE_SERVER_ADDRESS_IPV6="::1" \
TORTURE_SERVER_PORT=7777 \
tests/test_thread_echo_tcp_write_read


[1] https://cwrap.org/socket_wrapper.html
[2] https://git.cryptomilk.org/users/asn/socket_wrapper.git/log/?h=master-fix

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

Anoop C S <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #1 from Anoop C S <[hidden email]> ---
Created attachment 199095
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=199095&action=edit
server code

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
In reply to this post by bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

--- Comment #2 from Anoop C S <[hidden email]> ---
Created attachment 199096
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=199096&action=edit
client code

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
In reply to this post by bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

--- Comment #3 from Anoop C S <[hidden email]> ---
See attachment for a client-server program and Compile it as follows to
reproduce the issue:

# cc sv.c -o sv
# cc cl.c -lpthread -o cl

Run server in one shell:
# ./sv

Execute client program from another shell with thread count value:
# ./cl 10

Output samples:
with thread count = 5

client:
-------
$ ./cl 5
hello world
hello world
hello world
hello world
hello world

server:
-------
$ ./sv
1 CONNECTION/S ESTABLISHED
2 CONNECTION/S ESTABLISHED
3 CONNECTION/S ESTABLISHED
4 CONNECTION/S ESTABLISHED
5 CONNECTION/S ESTABLISHED
^C

with thread count = 10

client:
$ ./cl 10
Failed to connect to socket: Connection refused

server:
$ ./sv
1 CONNECTION/S ESTABLISHED
2 CONNECTION/S ESTABLISHED
3 CONNECTION/S ESTABLISHED
4 CONNECTION/S ESTABLISHED
5 CONNECTION/S ESTABLISHED
6 CONNECTION/S ESTABLISHED
7 CONNECTION/S ESTABLISHED
8 CONNECTION/S ESTABLISHED
^C

client program is written in such a way that it terminates on receiving refusal
during a connect() to server.

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
In reply to this post by bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

Konstantin Belousov <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--- Comment #4 from Konstantin Belousov <[hidden email]> ---
Your server limits the length of the accept queue to 5.

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
In reply to this post by bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

--- Comment #5 from Anoop C S <[hidden email]> ---
(In reply to Konstantin Belousov from comment #4)
Ah.. My bad.

Interestingly, echo server inside socket_wrapper code also have a backlog count
of 5. But the threaded test cases were all executed with 10 threads. This will
most probably be the reason for test failures.

I will verify and close this bug report accordingly.

Thanks for mentioning the wrong backlog count.

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

[Bug 231848] accept4() doesn't return a socket address when threading is involved

bugzilla-noreply
In reply to this post by bugzilla-noreply
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231848

Andreas Schneider <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|New                         |Closed
         Resolution|---                         |Not A Bug

--- Comment #6 from Andreas Schneider <[hidden email]> ---
Closing as this is an issue in the server implementation.

--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[hidden email]"