Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@gael-ian
Copy link
Contributor

Should fix #1269.

@coveralls
Copy link

coveralls commented Mar 13, 2020

Coverage Status

Coverage remained the same at ?% when pulling 32632be on gael-ian:fixes/sockets-as-fd into 1d626de on thumbor:fixes/6.7.x.

@gael-ian
Copy link
Contributor Author

I realized today that not only AF_UNIX sockets can be passed as file descriptors. AF_INET / AF_INET6 sockets created by systemd, Supervisor or another orchestrator will be passed the same way to dependent services.

In Python 3.8, we could have used socket(fileno=fd_number) to turn any file descriptor to a proper socket object but thumbor runs with Python 2.7 and there's no such option on socket().

Instead of trying to guess the correct family with some complex code, my proposition is to let users pass it as an argument and reuse the --port argument for this (as there no sense to pass a file descriptor and a port at the same time).

Hence a thumbor invocation would look like:

  • thumbor --fd /run/thumbor.sock (AF_UNIX socket passed by path)
  • thumbor --fd 3 --port 1 (AF_UNIX socket passed by file descriptor)
  • thumbor --ip 127.0.0.1 --port 8080 (AF_INET socket)
  • thumbor --fd 3 --port 2 (AF_INET socket passed by file descriptor)
  • thumbor --ip ::1 --port 8080 (AF_INET6 socket)
  • thumbor --fd 3 --port 10 (AF_INET6 socket passed by file descriptor)

1, 2 and 10 are numeric values respectively associated to Python's socket AF_UNIX, AF_INET and AF_INET6 constants.

@kkopachev
Copy link
Member

Knowing to pass numbers is too magical?

Another option to use https://github.com/tiran/socketfromfd which auto detects socket family and type.

@gael-ian
Copy link
Contributor Author

gael-ian commented Mar 16, 2020

Another option to use https://github.com/tiran/socketfromfd which auto detects socket family and type.

Much more interesting than argument cycling, indeed. I change the pull request to use it.

[Edit]
Promise, next time I try to contribute to a project in a language I don't know, I'll try to set up the development environment on my machine even for something supposed to not take more than 5LOC and 10mn... Sorry about that.

@kkopachev
Copy link
Member

That looks much cleaner, indeed. Would you fix the test please? Looks like it's trying to mock not existing anymore socket. That should now be fromfd mock instead

@gael-ian
Copy link
Contributor Author

Would you fix the test please?

Tomorrow. It's too late here to dig now into what are pip, virtualenv and the whole Python (2...) ecosystem.

@gael-ian
Copy link
Contributor Author

Sorry, the history of this branch is a mess but I had to rely on TravisCi to run tests.


I tried to follow contribution instructions but could not set up a development environment on my machine.

$ python -V
Python 3.8.2
$ pip -V
pip 20.0.2
$ poetry --version
Poetry version 1.0.5
$ pip install -e .[tests]
[...]
ERROR: remotecv 3.0.0 has requirement Pillow<8.0.0,>=7.0.0, but you'll have pillow 6.2.2 which is incompatible.
$ make test                        
[... many failing tests ...]
make[1]: *** [Makefile:57: unit] Segmentation fault (core dumped)
make[1]: Leaving directory '[...]/thumbor'
make: *** [Makefile:39: test] Error 2

I noticed that, even on TravisCi, remotecv has unmet dependencies.

@kkopachev
Copy link
Member

we should probably limit remotecv version to be below 3 for thumbor 6

@heynemann heynemann merged commit b727be9 into thumbor:fixes/6.7.x Mar 18, 2020
@heynemann
Copy link
Member

Should we cherry pick this to master?

@kkopachev
Copy link
Member

We should. Not sure if python's socket.socket(fileno=) works as expected in all pythons 3.

@heynemann
Copy link
Member

Do you mind cherry-picking it? If you can't, I'll find some time to do it.

Please be mindful of time spent here. Your safety and getting your loved ones safe is the most important thing. We can always work things out here later on! :) Hope you are safe and everyone you love as well.

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

Successfully merging this pull request may close these issues.

4 participants