question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deploying inside a process manager: must account for inherited socket family and type

See original GitHub issue

Hi,

I get an error when trying to run uvicorn with Circus, but only if using a socket with file descriptor (which I’d like to do to increase the number of processes).

circus.ini:

[socket:web]
host = 0.0.0.0
port = 80
[watcher:uvicorn]
cmd = uvicorn
# args = --host 0.0.0.0 --port 80 satemo.asgi:application 
# --> works ok
args = --fd $(circus.sockets.web) satemo.asgi:application 
# --> Fails
use_sockets = True
numprocesses = 1

Error:

File "c:\nss\venv\channels2\lib\site-packages\uvicorn\main.py", line 247, in startup
    sock = socket.fromfd(config.fd, socket.AF_UNIX, socket.SOCK_STREAM)
UnboundLocalError: local variable 'socket' referenced before assignment

Environment:

  • Windows 10
  • Python 3.6.5
  • uvicorn 0.4.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ldanielburrcommented, May 13, 2019

Hi, just bumping this issue to note that I get this error on macOS, running uvicorn under supervisord.

Interestingly, I tried adding “import socket” at the top of the file, as was done in https://github.com/encode/uvicorn/pull/296, but that did not solve the issue. What did work was adding “import socket” right after line 352:

elif config.fd is not None:
    # Use an existing socket, from a file descriptor.
    import socket
    sock = socket.fromfd(config.fd, socket.AF_UNIX, socket.SOCK_STREAM)
1reaction
jxrosselcommented, Mar 4, 2019

According to the socket module documentation:

The address family should be AF_INET (the default), AF_INET6, AF_UNIX, AF_CAN, AF_PACKET, or AF_RDS. The socket type should be SOCK_STREAM (the default), SOCK_DGRAM, SOCK_RAW or perhaps one of the other SOCK_ constants. The protocol number is usually zero and may be omitted or in the case where the address family is AF_CAN the protocol should be one of CAN_RAW, CAN_BCM or CAN_ISOTP.

I’d suggest to require full strings (e.g. ‘AF_INET’) and then get the constant values with getattr( socket, user_given_input ). To avoid following up with the versions of Python, I would not bother checking the arguments, but just return the exceptions given by socket, either at the getattr or socket.fromfd() levels.

Read more comments on GitHub >

github_iconTop Results From Across the Web

- socket()
This selects the protocol family that should be used. These families are defined in <sys/socket.h>. type: The type of socket you want to ......
Read more >
systemd.exec - Freedesktop.org
Unit configuration files for services, sockets, mount points, and swap devices share a subset of configuration options which define the execution environment of ......
Read more >
IBM Business Process Manager V8.0 Production Topologies
deployment manager is a specific type of IBM WebSphere Application Server whose primary task is the management and configuration of the cell in...
Read more >
WSASocketA function (winsock2.h) - Win32 apps
The WSASocket function creates a socket that is bound to a specific transport-service provider. (ANSI)
Read more >
Move 4.6 - Move User Guide - Nutanix Support Portal
The Move components are used in the following ways during various types of migration: ... Note: To deploy the Move VM, you must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found