I have a strange problem with unix socket (US) using so-called abstract namespaces when using Python and "pure" C (Python 3.x but looks like 2.x have the same problem). "Normal" socket works like a charm. With "abstract" one US my code works only when I'm using same "code platform" (C or Python).
First I thought it has something to do with memset
/ str(n)cpy
(see Can not connect to an abstract unix socket in python) but imho it's not that case.
Test matrix (srv - server, cli - client):
- srv + cli @ "abstract" unix sock:
- python + python = OK
- c + c = OK
- srv + cli @ "normal" unix sock:
- python + python = OK
- c + c = OK
- srv + cli @ "normal" unix sock:
- python + c = OK
- c + python = OK
- srv + cli @ "abstract" unix sock:
- python + c = FAIL [cli / strace output: ECONNREFUSED (Connection refused)]
- c + python = FAIL [cli / raised exception: socket.error: [Errno 111] Connection refused]
/proc/net/unix
/ lsof
or strace
show nothing unusual:
working "normal" socket C client:
// ...
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 110) = 0
// ...
misbehaving "abstract" socket C client:
// ...
socket(PF_LOCAL, SOCK_STREAM, 0) = 3
connect(3, {sa_family=AF_LOCAL, sun_path=@"/var/tmp/sock.tmp"}, 110) = -1 ECONNREFUSED (Connection refused)
// ...
Python bug or what...?
Gist with code samples for my test matrix: https://gist.github.com/soutys/ffbe2e76a86835a9cc6b
Original code / samples:
- C servers/clients - based on https://github.com/troydhanson/network/tree/master/unixdomain
- Python servers/clients - based on Python 3.X Unix Socket Example
Update 2015-11-02
More info about system and compilations:
- host system: Ubuntu 14.04.3 LTS (x64);
- all C test files compiled with
gcc
(example:gcc -Wall -Wextra -pedantic -o abs_cli abs_cli.c
); - all programs (both compiled and built-in python) run as non-root user;