'wsgi error: Address already in use - socketio/django/apache2

My project is created with React (create-react-app), React router (no webpack), -- Django (rest) and Socketio with eventlet on the backend.
I have 3 problems with deployment with apache2 - Everything worked perfectly on development:

Created 2 conf files, one for the frontend port 80 and one for the backend port 8000 - separetely they work fine relatively.

The problem I have with deployment:

  • Socket.io
    gives
[wsgi:error] 
eventlet.wsgi.server(eventlet.listen(("", 8000)), application, log_output=False)
sock.bind(addr)
Address already in use
  • checked what uses the port --> only apache2 and it gives the same result with any other port
  • tried to create a separate conf file for socket with port 5000 (changing the port in wsgi eventlet line), same result
    the socketFile.conf:
Listen 5000
<VirtualHost *:5000>
    ServerName www.example.com
    ServerAlias example.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /home/path/to/main/folder>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
WSGIDaemonProcess exampleSocket python-home=/home/path/to/venv python-path=/home/path/to/main/folder
WSGIProcessGroup exampleSocket
WSGIScriptAlias / /path/to/wsgi.py
</VirtualHost>
  • the next line is done by default with eventlet (reuse_addr=True, reuse_port=None) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

socketio_app/views.py

async_mode = None

import os
import socketio

basedir = os.path.dirname(os.path.realpath(__file__))
sio = socketio.Server(
    async_mode=async_mode, 
    logger=False, 
    cors_allowed_origins='http://localhost:3000'
)
thread = None
...

wsgi.py

import os
from django.core.wsgi import get_wsgi_application
from socketio_app.views import sio
import socketio
import eventlet
import eventlet.wsgi

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")

application = get_wsgi_application()

application = socketio.WSGIApp(sio, application)

eventlet.wsgi.server(eventlet.listen(("", 8000)), application, log_output=False)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source