Skip to content

Conversation

asmodehn
Copy link
Contributor

@asmodehn asmodehn commented Jun 6, 2025

Daphne should not touch the unix socket managed by supervisor, as supervisor will forward the traffic to --fd 0

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #520.

Description of Changes

The unix socket is managed by supervisor for this service, and the traffic is forwarded to fd 0 of the child processes launched.
Therefore daphne should not know about the unix socket, or it might disturb supervisor handling of it.
Ref: https://supervisord.org/configuration.html#fcgi-program-x-section-settings

Daphne should not touch the unix socket managed by supervisor, as supervisor will forward the traffic to `--fd 0`
Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ammubhave are you sure this fixes the issue?

I deployed this with daphne 4.2.0

(env) $ cat /etc/supervisor/conf.d/daphne.conf 
[fcgi-program:daphne]
user=www-data
socket=unix:///opt/openwisp2/daphne0.sock
directory=/opt/openwisp2
command=/opt/openwisp2/env/bin/daphne --fd 0 --access-log - --websocket_timeout 3600 --proxy-headers openwisp2.asgi:application
process_name=asgi%(process_num)d
numprocs=1
autostart=true
autorestart=true
stopsignal=INT
redirect_stderr=true
stdout_logfile=/opt/openwisp2/log/daphne.log
stdout_logfile_maxbytes=30MB
stdout_logfile_backups=5

(env) $ pip freeze | grep daphne
daphne==4.2.0
(env) $ tail -f log/daphne.log 
    nameOrPlugin, args, kw = _parseServer(description, None)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openwisp2/env/lib/python3.11/site-packages/twisted/internet/endpoints.py", line 1764, in _parseServer
    plugin = _matchPluginToPrefix(
             ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openwisp2/env/lib/python3.11/site-packages/twisted/internet/endpoints.py", line 1779, in _matchPluginToPrefix
    raise ValueError(f"Unknown endpoint type: '{endpointType}'")
ValueError: Unknown endpoint type: 'fd'
/usr/lib/python3/dist-packages/requests/__init__.py:109: RequestsDependencyWarning: urllib3 (2.4.0) or chardet (5.1.0)/charset_normalizer (3.0.1) doesn't match a supported version!
  warnings.warn(
/opt/openwisp2/env/lib/python3.11/site-packages/openwisp_utils/admin_theme/system_info.py:4: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources
/opt/openwisp2/env/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py:228: UserWarning: app_settings.USERNAME_REQUIRED is deprecated, use: app_settings.SIGNUP_FIELDS['username']['required']
  required=allauth_account_settings.USERNAME_REQUIRED,
/opt/openwisp2/env/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py:230: UserWarning: app_settings.EMAIL_REQUIRED is deprecated, use: app_settings.SIGNUP_FIELDS['email']['required']
  email = serializers.EmailField(required=allauth_account_settings.EMAIL_REQUIRED)
/opt/openwisp2/env/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py:288: UserWarning: app_settings.EMAIL_REQUIRED is deprecated, use: app_settings.SIGNUP_FIELDS['email']['required']
  email = serializers.EmailField(required=allauth_account_settings.EMAIL_REQUIRED)
Traceback (most recent call last):
  File "/opt/openwisp2/env/bin/daphne", line 8, in <module>
    sys.exit(CommandLineInterface.entrypoint())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openwisp2/env/lib/python3.11/site-packages/daphne/cli.py", line 171, in entrypoint
    cls().run(sys.argv[1:])
  File "/opt/openwisp2/env/lib/python3.11/site-packages/daphne/cli.py", line 291, in run
    self.server.run()
  File "/opt/openwisp2/env/lib/python3.11/site-packages/daphne/server.py", line 130, in run
    ep = serverFromString(reactor, str(socket_description))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openwisp2/env/lib/python3.11/site-packages/twisted/internet/endpoints.py", line 1844, in serverFromString
    nameOrPlugin, args, kw = _parseServer(description, None)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openwisp2/env/lib/python3.11/site-packages/twisted/internet/endpoints.py", line 1764, in _parseServer
    plugin = _matchPluginToPrefix(
             ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openwisp2/env/lib/python3.11/site-packages/twisted/internet/endpoints.py", line 1779, in _matchPluginToPrefix
    raise ValueError(f"Unknown endpoint type: '{endpointType}'")
ValueError: Unknown endpoint type: 'fd'
/usr/lib/python3/dist-packages/requests/__init__.py:109: RequestsDependencyWarning: urllib3 (2.4.0) or chardet (5.1.0)/charset_normalizer (3.0.1) doesn't match a supported version!
  warnings.warn(

I still see the same error.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in staging we have:

command=/opt/openwisp2/env/bin/daphne --fd 0 -u /opt/openwisp2/daphne%(process_num)d.sock --access-log - --websocket_timeout 3600 --proxy-headers openwisp2.asgi:application

If I restart the daphne process I don't see the error:

tail log/daphne.log -n 200

/usr/lib/python3/dist-packages/requests/__init__.py:109: RequestsDependencyWarning: urllib3 (2.4.0) or chardet (5.1.0)/charset_normalizer (3.0.1) doesn't match a supported version!
  warnings.warn(
/opt/openwisp2/env/lib/python3.11/site-packages/openwisp_utils/admin_theme/system_info.py:4: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources
/opt/openwisp2/env/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py:228: UserWarning: app_settings.USERNAME_REQUIRED is deprecated, use: app_settings.SIGNUP_FIELDS['username']['required']
  required=allauth_account_settings.USERNAME_REQUIRED,
/opt/openwisp2/env/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py:230: UserWarning: app_settings.EMAIL_REQUIRED is deprecated, use: app_settings.SIGNUP_FIELDS['email']['required']
  email = serializers.EmailField(required=allauth_account_settings.EMAIL_REQUIRED)
/opt/openwisp2/env/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py:288: UserWarning: app_settings.EMAIL_REQUIRED is deprecated, use: app_settings.SIGNUP_FIELDS['email']['required']
  email = serializers.EmailField(required=allauth_account_settings.EMAIL_REQUIRED)
/usr/lib/python3/dist-packages/requests/__init__.py:109: RequestsDependencyWarning: urllib3 (2.4.0) or chardet (5.1.0)/charset_normalizer (3.0.1) doesn't match a supported version!
  warnings.warn(

I restarted with:

supervisorctl restart daphne:asgi0

Is there another way to trigger the error?

@asmodehn
Copy link
Contributor Author

asmodehn commented Jun 6, 2025

This errors reminds me of : django/daphne#557, it might be worth it to force daphne<=4.1.2 for the time being ? It should get rid of this error in the log.

@asmodehn
Copy link
Contributor Author

asmodehn commented Jun 6, 2025

However for the error between supervisor and daphne, I haven't found any other way to reproduce it.

Also note it is only in the output of the supervisorctl start daphne:asgi0 command. The log is clean and the daphne processes seem to work as expected...

@asmodehn
Copy link
Contributor Author

asmodehn commented Jun 6, 2025

FYI, I just did a redeployment via the current master branch of ansible-openwisp2, and I can reproduce the issue.
My supervisor config for daphne changed. Like so :

root@hostname:/opt/openwisp2# pip list | grep supervisor
supervisor         4.2.5

root@hostname:/opt/openwisp2# source env/bin/activate

(env) root@hostname:/opt/openwisp2# pip list | grep daphne
daphne                           4.1.2

(env) root@hostname:/opt/openwisp2# supervisorctl status all
celery                           RUNNING   pid 108637, uptime 1 day, 5:43:37
celery_firmware_upgrader         RUNNING   pid 108724, uptime 1 day, 5:43:23
celery_monitoring                RUNNING   pid 108753, uptime 1 day, 5:43:17
celery_network                   RUNNING   pid 108694, uptime 1 day, 5:43:28
celerybeat                       RUNNING   pid 108666, uptime 1 day, 5:43:33
daphne:asgi0                     RUNNING   pid 225389, uptime 0:00:02
openwisp2                        RUNNING   pid 108783, uptime 1 day, 5:43:13

(env) root@hostname:/opt/openwisp2# pip list | grep daphne
daphne                           4.1.2

(env) root@hostname:/opt/openwisp2# pip list | grep -e 'Django\|Twisted'
Django                           4.2.22
Twisted                          24.11.0

(env) root@hostname:/opt/openwisp2# python --version
Python 3.11.2


(env) root@hostname:/opt/openwisp2# supervisorctl restart daphne:asgi0
daphne:asgi0: stopped
daphne:asgi0: ERROR (spawn error)

(env) root@hostname:/opt/openwisp2# cat /etc/supervisor/conf.d/daphne.conf 
[fcgi-program:daphne]
user=www-data
socket=unix:///opt/openwisp2/daphne0.sock
directory=/opt/openwisp2
command=/opt/openwisp2/env/bin/daphne --fd 0 -u /opt/openwisp2/daphne%(process_num)d.sock --access-log - --websocket_timeout 3600 --proxy-headers openwisp2.asgi:application
process_name=asgi%(process_num)d
numprocs=1
autostart=true
autorestart=true
stopsignal=INT
redirect_stderr=true
stdout_logfile=/opt/openwisp2/log/daphne.log
stdout_logfile_maxbytes=30MB
stdout_logfile_backups=5

(env) root@hostname:/opt/openwisp2# tail log/daphne.log 
192.168.254.10:0 - - [06/Jun/2025:19:09:53] "WSCONNECTING /ws/notification/" - -
192.168.254.10:0 - - [06/Jun/2025:19:09:53] "WSCONNECT /ws/notification/" - -
192.168.254.10:0 - - [06/Jun/2025:19:10:14] "WSCONNECTING /ws/notification/" - -
192.168.254.10:0 - - [06/Jun/2025:19:10:14] "WSCONNECT /ws/notification/" - -
192.168.254.10:0 - - [06/Jun/2025:19:10:59] "WSDISCONNECT /ws/notification/" - -
192.168.254.10:0 - - [06/Jun/2025:19:10:59] "WSDISCONNECT /ws/notification/" - -
/opt/openwisp2/env/lib/python3.11/site-packages/openwisp_utils/admin_theme/system_info.py:4: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources
/opt/openwisp2/env/lib/python3.11/site-packages/openwisp_utils/admin_theme/system_info.py:4: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources

Interestingly, my playbook passed successfully, but:

  • the Update supervisor configuration handler was triggered.
  • the Restart daphne handler was not triggered... (the one that should have failed with my current setup).
RUNNING HANDLER [openvpn : Start or restart OpenVPN service] *******************************************************************************************************
changed: [hostname]

RUNNING HANDLER [openwisp.openwisp2 : Update supervisor configuration] *********************************************************************************************
changed: [hostname]

RUNNING HANDLER [openwisp.openwisp2 : Restart nginx] ***************************************************************************************************************
changed: [hostname]

TASK [Check if redis-server is running] ****************************************************************************************************************************
ok: [hostname]

TASK [Check if redis is running] ***********************************************************************************************************************************
ok: [hostname]

TASK [Check if nginx is running] ***********************************************************************************************************************************
ok: [hostname]

TASK [Check if OpenWISP is running] ********************************************************************************************************************************
ok: [hostname]

=> to reproduce the failure with theplaybook, that handler needs to be notified somehow.

@asmodehn asmodehn marked this pull request as draft July 24, 2025 15:45
@asmodehn
Copy link
Contributor Author

Marking as draft because #520 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

[bug] daphne errors on supervisorctl restart daphne:asgi0

3 participants