Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid hardcoding socket type #358

Closed
iv-m opened this issue Nov 2, 2018 · 0 comments
Closed

Avoid hardcoding socket type #358

iv-m opened this issue Nov 2, 2018 · 0 comments

Comments

@iv-m
Copy link
Contributor

iv-m commented Nov 2, 2018

I've seen test failures for python package boto that uses HTTPPretty on my mipsel machines. It turns out that function fake_getaddrinfo from httppretty.core module hardcodes the values for socket family, type and protocol as integers 2, 1 and 6 respectively.

SOCK_DGRAM and SOCK_STREAM are system-specific constants. While you usually get

$ python -c 'import socket; print "SOCK_DGRAM=%s SOCK_STREAM=%s" % (socket.SOCK_DGRAM, socket.SOCK_STREAM);'
SOCK_DGRAM=2 SOCK_STREAM=1

on some systems, you get different values. For example, on most MIPS linux systems, the values are:

$ uname -a
Linux loongson3 4.14.32-l3-def-alt1 #1 SMP PREEMPT Tue Apr 10 11:58:16 UTC 2018 mips64 GNU/Linux
$ python -c 'import socket; print "SOCK_DGRAM=%s SOCK_STREAM=%s" % (socket.SOCK_DGRAM, socket.SOCK_STREAM);'
SOCK_DGRAM=1 SOCK_STREAM=2

So, the value 1 from fake_addrinfo gets interpreted as SOCK_DGRAM on such machines, and tests fail as SOCK_DGRAM type is not supported with IPPROTO_TCP.

To avoid such issues, constants from socket modules should be consistently used instead of the integer values.

iv-m added a commit to iv-m/HTTPretty that referenced this issue Nov 2, 2018
SOCK_DGRAM and SOCK_STREAM are system-specific constants,
so we should use the constants from socket module instead
of having their value right in the code.

Closes: gabrielfalcao#358
Signed-off-by: Ivan A. Melnikov <iv@altlinux.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant