Flask-Socketio takes extremely long to connect on Heroku - heroku

All code works perfectly fine on my local machine, just not on Heroku. Have read through many issues on github / other errors on Flask-socketio and nothing seems to work.
I left my browser running for about 20mins when using the eventlet setup and I saw the .on('connect') run correctly but none of the other parts of the code.
Here's my current procfile:
web: gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --chdir nickdima wsgi:app
heroku features:enable http-session-affinity
I've also tried this one with gevent:
web: gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --chdir nickdima wsgi:app
I've also tried this profile with eventlet:
web: gunicorn -k eventlet wsgi:app
and this profile with eventlet:
web: gunicorn --worker-class eventlet -w 1 --chdir nickdima wsgi:app
Here's my current requirements.txt file:
click==6.7
dnspython==1.15.0
eventlet==0.24.1
Flask==1.0.2
Flask-SocketIO==3.0.1
greenlet==0.4.14
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
monotonic==1.5
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1
I've also tried with gevent:
click==6.7
dnspython==1.15.0
gevent==1.2.2
gevent-socketio==0.3.6
gevent-websocket==0.10.1
Flask==1.0.2
Flask-SocketIO==3.0.1
greenlet==0.4.14
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
monotonic==1.5
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1
I've also tried eventlet / gevent with gunicorn 18.0.0 instead of 19.x.
Here is the javascript portion of code:
player_id = Math.round(Math.random() * 5000);
your_sock = io.connect('http://' + document.domain + ':' + location.port);
your_sock.on('connect', function(){
your_sock.emit('player_connect', {'id': player_id});
console.log('I have connected with ID ' + player_id);
});
your_sock.on('what_player', function(data){
console.log('recieved player number ' + data['player_number']);
if(data['id'] == player_id){
players[player_id] = {};
if(data['player_number'] == 1){
players[player_id]['num'] = data['player_number'];
players[player_id]['x'] = 10;
players[player_id]['y'] = 50;
} else {
players[player_id]['num'] = data['player_number'];
players[player_id]['x'] = 375;
players[player_id]['y'] = 50;
}
}
});
Here is the python Flask portion of code
#socketio.on('connect')
def handle_connect():
print('Player connected')
#socketio.on('player_connect')
def handle_player_connect(data):
print('received player_connect event')
data_base = get_db()
if data_base['count'] == 0:
data_base[data['id']] = {'player_number': 1}
data_base[data['id']]['x'] = 10
data_base[data['id']]['y'] = 50
data_base['count'] += 1
socketio.emit('what_player', {'id': data['id'], 'player_number': data_base['count']})
elif data_base['count'] == 1:
data_base[data['id']] = {'player_number': 2}
data_base[data['id']]['x'] = 375
data_base[data['id']]['y'] = 50
data_base['count'] += 1
socketio.emit('what_player', {'id': data['id'], 'player_number': data_base['count']})
#all players connected
print('SENDING ALL PLAYERS CONNECTED SIGNAL')
socketio.emit('all_players', data_base)
Here are my Heroku logs:
2018-09-03T05:46:30.740683+00:00 heroku[router]: at=info method=GET path="/test_pong/test_pong_game" host=www.nickdima.com request_id=d00254d0-f823-4a85-8e19-95f0087724f3 fwd="73.99.8.227" dyno=web.1 connect=0ms service=14ms status=200 bytes=999 protocol=http
2018-09-03T05:46:30.785061+00:00 heroku[router]: at=info method=GET path="/test_pong/static/js/paddle.js" host=www.nickdima.com request_id=01ff06e3-aaee-480f-941d-75626143bf4c fwd="73.99.8.227" dyno=web.1 connect=0ms service=5ms status=200 bytes=897 protocol=http
2018-09-03T05:46:30.795732+00:00 heroku[router]: at=info method=GET path="/test_pong/static/js/sketch.js" host=www.nickdima.com request_id=63c23be1-8ba7-4a6a-8100-bcc19146f42a fwd="73.99.8.227" dyno=web.1 connect=1ms service=8ms status=200 bytes=3601 protocol=http
2018-09-03T05:46:30.808960+00:00 heroku[router]: at=info method=GET path="/test_pong/static/libraries/p5.min.js" host=www.nickdima.com request_id=ce4d9796-efdc-402c-aae0-bc2b7c265816 fwd="73.99.8.227" dyno=web.1 connect=0ms service=34ms status=200 bytes=1135120 protocol=http
2018-09-03T05:46:30.788657+00:00 heroku[router]: at=info method=GET path="/test_pong/static/js/ball.js" host=www.nickdima.com request_id=7fa4fa84-8580-4a68-9560-834c627baa84 fwd="73.99.8.227" dyno=web.1 connect=1ms service=7ms status=200 bytes=410 protocol=http
2018-09-03T05:46:30.962821+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t=1535953590967-0" host=www.nickdima.com request_id=42bff075-2609-40da-8c9b-718fabd18003 fwd="73.99.8.227" dyno=web.1 connect=1ms service=2ms status=200 bytes=357 protocol=http
2018-09-03T05:46:31.098055+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1535953591019-1&sid=3fba645de8d7485eba3a26a83f84fc71" host=www.nickdima.com request_id=fce93aa4-04e4-4f67-8e88-064841c5edac fwd="73.99.8.227" dyno=web.1 connect=1ms service=84ms status=200 bytes=191 protocol=http
2018-09-03T05:46:56.090655+00:00 heroku[router]: at=info method=GET path="/test_pong/test_pong_game" host=www.nickdima.com request_id=db9cd6aa-a1d7-4efb-8385-5b6224517c40 fwd="73.99.8.227" dyno=web.1 connect=0ms service=3ms status=200 bytes=999 protocol=http
2018-09-03T05:46:56.177394+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t=1535953616185-0" host=www.nickdima.com request_id=546fc2cc-a82f-4155-922f-a1d39a9b5ba6 fwd="73.99.8.227" dyno=web.1 connect=0ms service=2ms status=200 bytes=357 protocol=http
2018-09-03T05:46:56.113312+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= websocket&sid=3fba645de8d7485eba3a26a83f84fc71" host=www.nickdima.com request_id=2717000f-8493-4c2d-9361-b2985064ef3d fwd="73.99.8.227" dyno=web.1 connect=0ms service=25044ms status=101 bytes=129 protocol=http
2018-09-03T05:46:56.383739+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1535953616311-1&sid=51e5baac529f43a98b522dd8272a9e5d" host=www.nickdima.com request_id=5d3e3c1d-208c-4ac6-983c-aa353157f483 fwd="73.99.8.227" dyno=web.1 connect=0ms service=88ms status=200 bytes=191 protocol=http
Current Attempt ------------ 2018-09-04
requirements.txt:
click==6.7
dnspython==1.15.0
eventlet==0.24.1
Flask==1.0.2
Flask-SocketIO==3.0.1
greenlet==0.4.14
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
monotonic==1.5
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1
procfile:
web: gunicorn --worker-class eventlet -w 1 --chdir nickdima wsgi:app
heroku logs:
2018-09-05T01:49:33.156384+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/test_pong/static/libraries/p5.min.js" host=www.nickdima.com request_id=21503aa3-189d-4352-9284-c9e4729358ea fwd="71.206.187.35" dyno=web.1 connect=1ms service=20ms status=503 bytes= protocol=http
2018-09-05T01:49:33.081561+00:00 heroku[router]: at=info method=GET path="/test_pong/test_pong_game" host=www.nickdima.com request_id=330001f4-39f0-4308-b000-029fe40028e0 fwd="71.206.187.35" dyno=web.1 connect=1ms service=12ms status=200 bytes=1176 protocol=http
2018-09-05T01:49:33.156250+00:00 heroku[router]: at=info method=GET path="/test_pong/static/js/sketch.js" host=www.nickdima.com request_id=4ad0a7c4-eee4-45f5-8328-6091278e0a84 fwd="71.206.187.35" dyno=web.1 connect=0ms service=14ms status=200 bytes=3645 protocol=http
2018-09-05T01:49:33.196748+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t=1536112174726-0" host=www.nickdima.com request_id=a86191db-769a-4035-8a76-25a4d6ae4e95 fwd="71.206.187.35" dyno=web.1 connect=1ms service=3ms status=200 bytes=419 protocol=http
2018-09-05T01:49:33.078629+00:00 app[web.1]: 10.101.253.141 - - [05/Sep/2018:01:49:33 +0000] "GET /test_pong/test_pong_game HTTP/1.1" 200 1014 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.142534+00:00 app[web.1]: Traceback (most recent call last):
2018-09-05T01:49:33.142529+00:00 app[web.1]: [2018-09-05 01:49:33 +0000] [8] [ERROR] Socket error processing request.
2018-09-05T01:49:33.142536+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 66, in handle
2018-09-05T01:49:33.142537+00:00 app[web.1]: six.reraise(*sys.exc_info())
2018-09-05T01:49:33.142541+00:00 app[web.1]: raise value
2018-09-05T01:49:33.142539+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/six.py", line 625, in reraise
2018-09-05T01:49:33.142543+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 56, in handle
2018-09-05T01:49:33.142545+00:00 app[web.1]: self.handle_request(listener_name, req, client, addr)
2018-09-05T01:49:33.142547+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 129, in handle_request
2018-09-05T01:49:33.142548+00:00 app[web.1]: six.reraise(*sys.exc_info())
2018-09-05T01:49:33.142550+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/six.py", line 625, in reraise
2018-09-05T01:49:33.142552+00:00 app[web.1]: raise value
2018-09-05T01:49:33.142557+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 403, in write_file
2018-09-05T01:49:33.142555+00:00 app[web.1]: resp.write_file(respiter)
2018-09-05T01:49:33.142553+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 112, in handle_request
2018-09-05T01:49:33.142558+00:00 app[web.1]: if not self.sendfile(respiter):
2018-09-05T01:49:33.142943+00:00 app[web.1]: BlockingIOError: [Errno 11] Resource temporarily unavailable
2018-09-05T01:49:33.142560+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 393, in sendfile
2018-09-05T01:49:33.142562+00:00 app[web.1]: sent += sendfile(sockno, fileno, offset + sent, count)
2018-09-05T01:49:33.152718+00:00 app[web.1]: 10.30.67.242 - - [05/Sep/2018:01:49:33 +0000] "GET /test_pong/static/js/sketch.js HTTP/1.1" 200 0 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.156363+00:00 app[web.1]: 10.69.229.32 - - [05/Sep/2018:01:49:33 +0000] "GET /test_pong/static/js/ball.js HTTP/1.1" 200 0 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.159465+00:00 app[web.1]: 10.143.137.225 - - [05/Sep/2018:01:49:33 +0000] "GET /test_pong/static/js/paddle.js HTTP/1.1" 200 0 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.196095+00:00 app[web.1]: 10.143.137.225 - - [05/Sep/2018:01:49:33 +0000] "GET /socket.io/?EIO=3&transport=polling&t=1536112174726-0 HTTP/1.1" 200 119 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.290914+00:00 app[web.1]: 10.69.229.32 - - [05/Sep/2018:01:49:33 +0000] "GET /favicon.ico HTTP/1.1" 404 233 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.160071+00:00 heroku[router]: at=info method=GET path="/test_pong/static/js/ball.js" host=www.nickdima.com request_id=8b6f3933-5a17-473c-b9d6-c6bb2838dede fwd="71.206.187.35" dyno=web.1 connect=1ms service=18ms status=200 bytes=454 protocol=http
2018-09-05T01:49:33.294742+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=www.nickdima.com request_id=a7eaa94f-6ef2-4b9c-a121-54ed25100202 fwd="71.206.187.35" dyno=web.1 connect=1ms service=3ms status=404 bytes=386 protocol=http
2018-09-05T01:49:33.382911+00:00 app[web.1]: 10.143.137.225 - - [05/Sep/2018:01:49:33 +0000] "GET /socket.io/?EIO=3&transport=polling&t=1536112174796-1&sid=cf08a35743824c3c97331953a2495b5e HTTP/1.1" 200 4 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T01:49:33.383458+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1536112174796-1&sid=cf08a35743824c3c97331953a2495b5e" host=www.nickdima.com request_id=39a7b0de-e421-494a-b619-6312d73cab03 fwd="71.206.187.35" dyno=web.1 connect=1ms service=133ms status=200 bytes=254 protocol=http
2018-09-05T01:50:03.424073+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1536112174962-2&sid=cf08a35743824c3c97331953a2495b5e" host=www.nickdima.com request_id=8b2628fd-06c4-44b8-9db9-d4487288fa7e fwd="71.206.187.35" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http
2018-09-05T01:50:28.429256+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=GET path= "/socket.io/?EIO= 3&transport= websocket&sid=cf08a35743824c3c97331953a2495b5e" host=www.nickdima.com request_id=b134b681-44cd-4a2f-b67a-f74a660a5d4d fwd="71.206.187.35" dyno=web.1 connect=3ms service=55129ms status=503 bytes= protocol=http
2018-09-05T01:50:33.450013+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1536112174962-2&sid=cf08a35743824c3c97331953a2495b5e" host=www.nickdima.com request_id=d2f5ea3e-fa45-41c1-b9a0-79be30409cd7 fwd="71.206.187.35" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=http
chrome console (attempt 1):
chrome console (attempt 2 after refreshing):
When I refresh my javascript black canvas loads but I do not see any errors in developer tab. I host a lot of other simple javascript games on my site and i'm noticing when i add the "--worker-class eventlet -w 1" to my procfile, a lot of these games fail to load and you need to keep refreshing. The errors are always "ERR_CONTENT_MISTMACH" when they don't load.
Added logging / preload to Gunicorn and saw these additional logs:
2018-09-05T03:23:07.362850+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-05T03:23:07.382021+00:00 app[web.1]: [2018-09-05 03:23:07 +0000] [4] [INFO] Handling signal: term
2018-09-05T03:23:11.503047+00:00 heroku[web.1]: Starting process with command `gunicorn --worker-class eventlet -w 1 --no-sendfile --log-file=- --preload --chdir nickdima wsgi:app`
2018-09-05T03:23:15.192348+00:00 heroku[web.1]: State changed from starting to up
2018-09-05T03:23:14.966375+00:00 app[web.1]: [2018-09-05 03:23:14 +0000] [4] [INFO] Starting gunicorn 19.9.0
2018-09-05T03:23:14.968846+00:00 app[web.1]: [2018-09-05 03:23:14 +0000] [4] [INFO] Listening at: http://0.0.0.0:57792 (4)
2018-09-05T03:23:14.969056+00:00 app[web.1]: [2018-09-05 03:23:14 +0000] [4] [INFO] Using worker: eventlet
2018-09-05T03:23:14.979072+00:00 app[web.1]: [2018-09-05 03:23:14 +0000] [9] [INFO] Booting worker with pid: 9
2018-09-05T03:23:26.714115+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-05T03:23:37.443586+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 30 seconds of SIGTERM
2018-09-05T03:23:37.443586+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2018-09-05T03:23:37.555124+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= websocket&sid=bde8a4bfe1f747b482f12c8df36370a2" host=www.nickdima.com request_id=39dec25b-b8b2-4c2c-b290-fa30f7077344 fwd="71.206.187.35" dyno=web.1 connect=0ms service=403842ms status=101 bytes=202 protocol=http
2018-09-05T03:23:37.565259+00:00 heroku[web.1]: Process exited with status 137
2018-09-05T03:23:39.081372+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t=1536117820575-3" host=www.nickdima.com request_id=ef81fcd4-a159-49a1-b64b-a96ca9c28eb3 fwd="71.206.187.35" dyno=web.1 connect=1ms service=5ms status=200 bytes=419 protocol=http
2018-09-05T03:23:39.169122+00:00 heroku[router]: at=info method=POST path= "/socket.io/?EIO= 3&transport= polling&t= 1536117820758-4&sid=b13c7d70371145e1b7dc939a83ac835b" host=www.nickdima.com request_id=2e698d4e-1ffc-48ca-99bb-8d7e9d9879ec fwd="71.206.187.35" dyno=web.1 connect=3ms service=4ms status=200 bytes=260 protocol=http
2018-09-05T03:23:39.083359+00:00 app[web.1]: 10.178.65.194 - - [05/Sep/2018:03:23:39 +0000] "GET /socket.io/?EIO=3&transport=polling&t=1536117820575-3 HTTP/1.1" 200 119 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T03:23:39.170709+00:00 app[web.1]: 10.178.65.194 - - [05/Sep/2018:03:23:39 +0000] "POST /socket.io/?EIO=3&transport=polling&t=1536117820758-4&sid=b13c7d70371145e1b7dc939a83ac835b HTTP/1.1" 200 2 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T03:23:39.450831+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1536117820764-5&sid=b13c7d70371145e1b7dc939a83ac835b" host=www.nickdima.com request_id=725fd364-b928-4535-9ccb-dd53cca366b2 fwd="71.206.187.35" dyno=web.1 connect=1ms service=248ms status=200 bytes=254 protocol=http
2018-09-05T03:23:39.455779+00:00 app[web.1]: 10.7.181.120 - - [05/Sep/2018:03:23:39 +0000] "GET /socket.io/?EIO=3&transport=polling&t=1536117820764-5&sid=b13c7d70371145e1b7dc939a83ac835b HTTP/1.1" 200 4 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T03:23:44.223695+00:00 app[web.1]: 10.7.181.120 - - [05/Sep/2018:03:23:44 +0000] "GET /test_pong/test_pong_game HTTP/1.1" 200 1022 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T03:23:44.218653+00:00 heroku[router]: at=info method=GET path="/test_pong/test_pong_game" host=www.nickdima.com request_id=9ffcf7cc-fdc3-4be0-bc67-379ba33c1b8c fwd="71.206.187.35" dyno=web.1 connect=1ms service=39ms status=200 bytes=1184 protocol=http
2018-09-05T03:23:44.966848+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= websocket&sid=b13c7d70371145e1b7dc939a83ac835b" host=www.nickdima.com request_id=6f1bf11c-136c-4bb5-809b-69ebab24bd48 fwd="71.206.187.35" dyno=web.1 connect=3ms service=5758ms status=101 bytes=202 protocol=http
New Session as of 2018-09-05 ---------------------
same requirements.txt as 9/4 update
new procfile:
web: gunicorn --worker-class eventlet -w 1 --no-sendfile --log-level=DEBUG --log-file=- --preload --chdir nickdima wsgi:app
No longer seeing Content mismatch error and my console is logging a message that only should run if the socket connects via the following code:
player_id = Math.round(Math.random() * 5000);
your_sock = io.connect('http://' + document.domain + ':' + location.port + '/'); //io.connect(''); //io.connect('http://' + document.domain + ':' + location.port);
your_sock.on('connect', function(){
your_sock.emit('player_connect', {'id': player_id});
console.log('I have connected with ID ' + player_id);
});
But the server is not receiving the 'player_connect' emit:
#socker.on('player_connect')
def handle_player_connect(data):
print('received player_connect event')
data_base = get_db()
if data_base['count'] == 0:
data_base[data['id']] = {'player_number': 1}
data_base[data['id']]['x'] = 10
data_base[data['id']]['y'] = 50
data_base['count'] += 1
socker.emit('what_player', {'id': data['id'], 'player_number': data_base['count']})
elif data_base['count'] == 1:
data_base[data['id']] = {'player_number': 2}
data_base[data['id']]['x'] = 375
data_base[data['id']]['y'] = 50
data_base['count'] += 1
socker.emit('what_player', {'id': data['id'], 'player_number': data_base['count']})
#all players connected
print('SENDING ALL PLAYERS CONNECTED SIGNAL')
socker.emit('all_players', data_base)
Heroku logs aren't showing anything helpful from what i can see:
18-09-05T21:54:04.640810+00:00 heroku[router]: at=info method=GET path="/home/" host=www.nickdima.com request_id=445a34ed-abf7-4336-82ab-4aabe79353b8 fwd="71.206.187.35" dyno=web.1 connect=1ms service=20ms status=200 bytes=11179 protocol=http
2018-09-05T21:54:04.568250+00:00 app[web.1]: [2018-09-05 21:54:04 +0000] [9] [DEBUG] GET /
2018-09-05T21:54:04.583348+00:00 app[web.1]: 10.45.224.215 - - [05/Sep/2018:21:54:04 +0000] "GET / HTTP/1.1" 302 219 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:04.585672+00:00 app[web.1]: [2018-09-05 21:54:04 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:04.621195+00:00 app[web.1]: [2018-09-05 21:54:04 +0000] [9] [DEBUG] GET /home/
2018-09-05T21:54:04.638969+00:00 app[web.1]: 10.45.224.215 - - [05/Sep/2018:21:54:04 +0000] "GET /home/ HTTP/1.1" 200 11016 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:04.639359+00:00 app[web.1]: [2018-09-05 21:54:04 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:04.713340+00:00 app[web.1]: [2018-09-05 21:54:04 +0000] [9] [DEBUG] GET /home/assets/images/gallery00.jpg
2018-09-05T21:54:04.721688+00:00 app[web.1]: 10.45.224.215 - - [05/Sep/2018:21:54:04 +0000] "GET /home/assets/images/gallery00.jpg HTTP/1.1" 404 233 "http://www.nickdima.com/home/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:04.722818+00:00 app[web.1]: [2018-09-05 21:54:04 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:04.721980+00:00 heroku[router]: at=info method=GET path="/home/assets/images/gallery00.jpg" host=www.nickdima.com request_id=1936951c-a1ff-4c3f-b45e-62c05beef586 fwd="71.206.187.35" dyno=web.1 connect=1ms service=28ms status=404 bytes=386 protocol=http
2018-09-05T21:54:07.057783+00:00 heroku[router]: at=info method=GET path="/test_pong/test_pong_game" host=www.nickdima.com request_id=0f55eaef-cee3-42ae-902a-5f0ed2e478a0 fwd="71.206.187.35" dyno=web.1 connect=1ms service=6ms status=200 bytes=1184 protocol=http
2018-09-05T21:54:07.052890+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] GET /test_pong/test_pong_game
2018-09-05T21:54:07.056222+00:00 app[web.1]: 10.45.224.215 - - [05/Sep/2018:21:54:07 +0000] "GET /test_pong/test_pong_game HTTP/1.1" 200 1022 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:07.056441+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:07.561324+00:00 heroku[router]: at=info method=POST path= "/socket.io/?EIO= 3&transport= polling&t= 1536184448912-1&sid=f03a4525f29b4ccb852eb78e023f0876" host=www.nickdima.com request_id=222d42b3-3b15-4c22-be91-15f53536525d fwd="71.206.187.35" dyno=web.1 connect=1ms service=6ms status=200 bytes=260 protocol=http
2018-09-05T21:54:07.592902+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t= 1536184448914-2&sid=f03a4525f29b4ccb852eb78e023f0876" host=www.nickdima.com request_id=238b5616-398f-4eef-8f1b-6dc11b89f19c fwd="71.206.187.35" dyno=web.1 connect=0ms service=34ms status=200 bytes=254 protocol=http
2018-09-05T21:54:07.514706+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] GET /socket.io/
2018-09-05T21:54:07.516436+00:00 app[web.1]: 10.45.224.215 - - [05/Sep/2018:21:54:07 +0000] "GET /socket.io/?EIO=3&transport=polling&t=1536184448866-0 HTTP/1.1" 200 119 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:07.517309+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:07.556698+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] POST /socket.io/
2018-09-05T21:54:07.559278+00:00 app[web.1]: 10.45.224.215 - - [05/Sep/2018:21:54:07 +0000] "POST /socket.io/?EIO=3&transport=polling&t=1536184448912-1&sid=f03a4525f29b4ccb852eb78e023f0876 HTTP/1.1" 200 2 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:07.559734+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:07.561340+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] GET /socket.io/
2018-09-05T21:54:07.572150+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] GET /socket.io/
2018-09-05T21:54:07.593532+00:00 app[web.1]: 10.11.200.153 - - [05/Sep/2018:21:54:07 +0000] "GET /socket.io/?EIO=3&transport=polling&t=1536184448914-2&sid=f03a4525f29b4ccb852eb78e023f0876 HTTP/1.1" 200 4 "http://www.nickdima.com/test_pong/test_pong_game" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
2018-09-05T21:54:07.594556+00:00 app[web.1]: [2018-09-05 21:54:07 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:54:07.518196+00:00 heroku[router]: at=info method=GET path= "/socket.io/?EIO= 3&transport= polling&t=1536184448866-0" host=www.nickdima.com request_id=f253094f-a8a5-4572-a751-deca8289c4ea fwd="71.206.187.35" dyno=web.1 connect=1ms service=8ms status=200 bytes=419 protocol=http
2018-09-05T21:54:44.668853+00:00 app[web.1]: [2018-09-05 21:54:44 +0000] [9] [DEBUG] Closing connection.
2018-09-05T21:56:53.121104+00:00 app[web.1]: [2018-09-05 21:56:53 +0000] [9] [DEBUG] Closing connection.
I've added this code to server:
#socker.on('connect')
def handle_connect():
print('THE HANDLE CONNECT FUNCTION WAS WRITTEN')
try:
socker.emit('testing', {'hello': 'hi'})
except Exception as e:
print(e)
and it does not get logged to heroku logs yet other logs do. Somehow the javascript socket.on('connect') function is running but the server side function is not running

Related

Is there a string length limit in heroku when inserting data into a postgresql active records database in ruby?

I am currently running into a problem where on my local machine, I can create and insert a record into a table called Devices but on my heroku deploy, I cannot create a record if the length of my identifier and push_token are too long.
The device table migration I am using is pasted below.
class CreateDevices < ActiveRecord::Migration[6.1]
def change
create_table :devices do |t|
t.string :identifier, null: false
t.string :push_token, null: false
end
end
end
I tried a simple test with an endpoint to see if records were created with
get "/test/devices/:device_id/:push_tokens" do
Device.create(identifier: params[:device_id], push_token: params[:push_tokens])
puts "device_count is"
puts Device.count
end
On my local machine, if i set params[:device_id] and params[:push_tokens] to for example,
278b5d5668b7e2df3b686e0c0d19a0b9 and 1319f7e0f6dd345304c5e8e84e5ec3f52213b8f485e4783861b476373f000dde respectively the active record updates and the device count updates with it. However if i try these values on the heroku deploy, the device count is not updated and no record is created.
I am struggling to figure out whether this is a problem with my postgresql plan on heroku, if my code is not waiting for the record to be created or something entirely different.
2022-09-23T13:47:45.399683+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789/123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=21779202-b9b6-4e02-9195-6ead6cc63ba6 fwd="147.12.186.203" dyno=web.1 connect=0ms service=9ms status=200 bytes=191 protocol=https
2022-09-23T13:47:45.394194+00:00 app[web.1]: device_count is
2022-09-23T13:47:45.395126+00:00 app[web.1]: 8
2022-09-23T13:47:59.284900+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789/123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=04ef6dab-71c3-4237-b52f-bf2ea16576f0 fwd="147.12.186.203" dyno=web.1 connect=0ms service=7ms status=200 bytes=191 protocol=https
2022-09-23T13:47:59.279643+00:00 app[web.1]: device_count is
2022-09-23T13:47:59.280339+00:00 app[web.1]: 9
2022-09-23T13:48:17.720446+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789/123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=1c221b82-f142-44a0-b0ec-774a8515365a fwd="147.12.186.203" dyno=web.1 connect=0ms service=9ms status=200 bytes=191 protocol=https
2022-09-23T13:48:17.715182+00:00 app[web.1]: device_count is
2022-09-23T13:48:17.715917+00:00 app[web.1]: 10
2022-09-23T13:48:35.566064+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789123456789/123456789123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=2539f65b-7f82-42dc-9c4e-c078b93412d1 fwd="147.12.186.203" dyno=web.1 connect=0ms service=6ms status=200 bytes=191 protocol=https
2022-09-23T13:48:35.560941+00:00 app[web.1]: device_count is
2022-09-23T13:48:35.561519+00:00 app[web.1]: 11
2022-09-23T13:49:00.943300+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789123456789123456789/123456789123456789123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=01acc954-8cf9-4327-8e84-b1958298b14d fwd="147.12.186.203" dyno=web.1 connect=0ms service=8ms status=200 bytes=191 protocol=https
2022-09-23T13:49:00.937948+00:00 app[web.1]: device_count is
2022-09-23T13:49:00.938685+00:00 app[web.1]: 12
2022-09-23T13:49:52.814962+00:00 heroku[router]: at=info method=GET path="/test/devices/123456789123456789123456789123456789123456789123456789/123456789123456789123456789123456789123456789123456789123456789123456789" host=japsoc-passes-server-2.herokuapp.com request_id=c834c2df-b822-4796-b8ae-ab29cce6bdc2 fwd="147.12.186.203" dyno=web.1 connect=0ms service=5ms status=200 bytes=191 protocol=https
2022-09-23T13:49:52.809811+00:00 app[web.1]: device_count is
2022-09-23T13:49:52.810427+00:00 app[web.1]: 12
I did some testing with the endpoint on the heroku deploy and it seems that at some point, if the string is too long for either the identifier or the push_token, no record is created but i still receive a status 200. I would greatly appreciate any help on this matter!
Turns out after using Device.create! instead of Device.create, the reason why a device was not created was because either the device_id had already been taken or push_token had already been taken and it was a problem with my device models rather than active records.

heroku error Process exited with status 3

I was trying to create an app with the learned model with flask through Heroku env
2019-11-17T01:24:29.506868+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-11-17T01:24:29.506869+00:00 app[web.1]: worker.init_process()
2019-11-17T01:24:29.506871+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 133, in init_process
2019-11-17T01:24:29.506872+00:00 app[web.1]: self.load_wsgi()
2019-11-17T01:24:29.506874+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 142, in load_wsgi
2019-11-17T01:24:29.506875+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-11-17T01:24:29.506877+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-17T01:24:29.506878+00:00 app[web.1]: self.callable = self.load()
2019-11-17T01:24:29.506880+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-11-17T01:24:29.506881+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-17T01:24:29.506883+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-11-17T01:24:29.506884+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-17T01:24:29.506885+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 331, in import_app
2019-11-17T01:24:29.506887+00:00 app[web.1]: mod = importlib.import_module(module)
2019-11-17T01:24:29.506889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/init.py", line 126, in import_module
2019-11-17T01:24:29.506890+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-11-17T01:24:29.506892+00:00 app[web.1]: File "", line 994, in _gcd_import
2019-11-17T01:24:29.506893+00:00 app[web.1]: File "", line 971, in _find_and_load
2019-11-17T01:24:29.506894+00:00 app[web.1]: File "", line 953, in _find_and_load_unlocked
2019-11-17T01:24:29.506896+00:00 app[web.1]: ModuleNotFoundError: No module named 'application'
2019-11-17T01:24:29.506986+00:00 app[web.1]: [2019-11-17 01:24:29 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-11-17T01:24:29.533341+00:00 app[web.1]: [2019-11-17 01:24:29 +0000] [4] [INFO] Shutting down: Master
2019-11-17T01:24:29.533421+00:00 app[web.1]: [2019-11-17 01:24:29 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-11-17T01:24:29.601346+00:00 heroku[web.1]: Process exited with status 3
2019-11-17T04:07:39.025573+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ny-cab-fare-prediction-api.herokuapp.com request_id=c63bd1ad-8314-452b-b9ea-5f72a0c524cf fwd="103.5.134.31" dyno= connect= service= status=503 bytes= protocol=https
2019-11-17T04:07:39.936881+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ny-cab-fare-prediction-api.herokuapp.com request_id=4dd5e588-dd2c-486e-a998-6bd6cbf5298d fwd="103.5.134.31" dyno= connect= service= status=503 bytes= protocol=https
2019-11-17T05:18:07.225765+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ny-cab-fare-prediction-api.herokuapp.com request_id=fc42949c-9825-4ecb-877e-b13983bbb948 fwd="103.5.134.31" dyno= connect= service= status=503 bytes= protocol=https
2019-11-17T05:18:07.906552+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ny-cab-fare-prediction-api.herokuapp.com request_id=3e214acf-6344-418e-ac4f-9fc064471329 fwd="103.5.134.31" dyno= connect= service= status=503 bytes= protocol=https
2019-11-17T05:18:33.000000+00:00 app[api]: Build started by user yegavintin#gmail.com
2019-11-17T05:19:07.395350+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-17T05:19:07.061059+00:00 app[api]: Deploy 1345edea by user yegavintin#gmail.com
2019-11-17T05:19:07.061059+00:00 app[api]: Release v7 created by user yegavintin#gmail.com
2019-11-17T05:19:14.659794+00:00 heroku[web.1]: Starting process with command gunicorn application:app
2019-11-17T05:19:17.128085+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-17T05:19:17.132088+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-17T05:19:16.965846+00:00 app[web.1]: [2019-11-17 05:19:16 +0000] [4] [INFO] Starting gunicorn 20.0.0
2019-11-17T05:19:16.966852+00:00 app[web.1]: [2019-11-17 05:19:16 +0000] [4] [INFO] Listening at: http://0.0.0.0:32063 (4)
2019-11-17T05:19:16.967039+00:00 app[web.1]: [2019-11-17 05:19:16 +0000] [4] [INFO] Using worker: sync
2019-11-17T05:19:16.971935+00:00 app[web.1]: [2019-11-17 05:19:16 +0000] [11] [INFO] Booting worker with pid: 11
2019-11-17T05:19:16.977535+00:00 app[web.1]: [2019-11-17 05:19:16 +0000] [11] [ERROR] Exception in worker process
2019-11-17T05:19:16.977539+00:00 app[web.1]: Traceback (most recent call last):
2019-11-17T05:19:16.977542+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-11-17T05:19:16.977544+00:00 app[web.1]: worker.init_process()
2019-11-17T05:19:16.977546+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 133, in init_process
2019-11-17T05:19:16.977548+00:00 app[web.1]: self.load_wsgi()
2019-11-17T05:19:16.977550+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 142, in load_wsgi
2019-11-17T05:19:16.977552+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-11-17T05:19:16.977554+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-17T05:19:16.977556+00:00 app[web.1]: self.callable = self.load()
2019-11-17T05:19:16.977558+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-11-17T05:19:16.977560+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-17T05:19:16.977562+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-11-17T05:19:16.977564+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-17T05:19:16.977566+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 331, in import_app
2019-11-17T05:19:16.977568+00:00 app[web.1]: mod = importlib.import_module(module)
2019-11-17T05:19:16.977570+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/init.py", line 126, in import_module
2019-11-17T05:19:16.977573+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-11-17T05:19:16.977575+00:00 app[web.1]: File "", line 994, in _gcd_import
2019-11-17T05:19:16.977577+00:00 app[web.1]: File "", line 971, in _find_and_load
2019-11-17T05:19:16.977579+00:00 app[web.1]: File "", line 953, in _find_and_load_unlocked
2019-11-17T05:19:16.977587+00:00 app[web.1]: ModuleNotFoundError: No module named 'application'
2019-11-17T05:19:16.977747+00:00 app[web.1]: [2019-11-17 05:19:16 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-11-17T05:19:17.019314+00:00 app[web.1]: [2019-11-17 05:19:17 +0000] [4] [INFO] Shutting down: Master
2019-11-17T05:19:17.019530+00:00 app[web.1]: [2019-11-17 05:19:17 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-11-17T05:19:17.104870+00:00 heroku[web.1]: Process exited with status 3
2019-11-17T05:19:25.549819+00:00 heroku[web.1]: Starting process with command gunicorn application:app
2019-11-17T05:19:27.758021+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-17T05:19:27.630416+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [4] [INFO] Starting gunicorn 20.0.0
2019-11-17T05:19:27.630968+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [4] [INFO] Listening at: http://0.0.0.0:30205 (4)
2019-11-17T05:19:27.631086+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [4] [INFO] Using worker: sync
2019-11-17T05:19:27.636390+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [11] [INFO] Booting worker with pid: 11
2019-11-17T05:19:27.642955+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [11] [ERROR] Exception in worker process
2019-11-17T05:19:27.642958+00:00 app[web.1]: Traceback (most recent call last):
2019-11-17T05:19:27.642959+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-11-17T05:19:27.642964+00:00 app[web.1]: worker.init_process()
2019-11-17T05:19:27.642965+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 133, in init_process
2019-11-17T05:19:27.642967+00:00 app[web.1]: self.load_wsgi()
2019-11-17T05:19:27.642968+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 142, in load_wsgi
2019-11-17T05:19:27.642970+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-11-17T05:19:27.642972+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-11-17T05:19:27.642973+00:00 app[web.1]: self.callable = self.load()
2019-11-17T05:19:27.642975+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2019-11-17T05:19:27.642976+00:00 app[web.1]: return self.load_wsgiapp()
2019-11-17T05:19:27.642978+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2019-11-17T05:19:27.642979+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-11-17T05:19:27.642980+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 331, in import_app
2019-11-17T05:19:27.642982+00:00 app[web.1]: mod = importlib.import_module(module)
2019-11-17T05:19:27.642983+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/init.py", line 126, in import_module
2019-11-17T05:19:27.642985+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-11-17T05:19:27.642987+00:00 app[web.1]: File "", line 994, in _gcd_import
2019-11-17T05:19:27.642988+00:00 app[web.1]: File "", line 971, in _find_and_load
2019-11-17T05:19:27.642990+00:00 app[web.1]: File "", line 953, in _find_and_load_unlocked
2019-11-17T05:19:27.642994+00:00 app[web.1]: ModuleNotFoundError: No module named 'application'
2019-11-17T05:19:27.643170+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-11-17T05:19:27.682204+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [4] [INFO] Shutting down: Master
2019-11-17T05:19:27.682293+00:00 app[web.1]: [2019-11-17 05:19:27 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-11-17T05:19:27.742185+00:00 heroku[web.1]: Process exited with status 3
2019-11-17T05:19:28.000000+00:00 app[api]: Build succeeded
2019-11-17T05:21:57.875588+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ny-cab-fare-prediction-api.herokuapp.com request_id=cf5e1a0c-7b15-4344-a7d6-1e9d18950322 fwd="103.5.134.31" dyno= connect= service= status=503 bytes= protocol=https
2019-11-17T05:21:58.581392+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ny-cab-fare-prediction-api.herokuapp.com request_id=3ab91fae-db55-4a87-a571-64dc5d3dafb9 fwd="103.5.134.31" dyno= connect= service= status=503 bytes= protocol=https
Not sure why you have web: gunicorn application:app this in Procefile. Your repo doesn't have application module.
Please change you Procfile contents to web: gunicorn app:app.

Understand heroku's log

Can someone explain me the different lines in this piece of Heroku's log while my Facebook Messenger bot is running (and people interacting)
2018-08-19T12:21:53.976999+00:00 app[web.1]: 10.124.6.113 - - [19/Aug/2018:12:21:53 +0000] "POST /webhook HTTP/1.1" 200 2 "-" "facebookexternalua"
2018-08-19T12:21:54.060862+00:00 app[web.1]: 10.8.0.31 - - [19/Aug/2018:12:21:54 +0000] "POST /webhook HTTP/1.1" 200 2 "-" "facebookexternalua"
2018-08-19T12:21:53.977357+00:00 heroku[router]: at=info method=POST path="/webhook" host=some-app.herokuapp.com request_id=9691c0bc-43c7-4a5e-83c1-c636a4cc2789 fwd="31.13.115.9" dyno=web.1 connect=0ms service=462ms status=200 bytes=161 protocol=https
2018-08-19T12:21:54.062745+00:00 heroku[router]: at=info method=POST path="/webhook" host=some-app.herokuapp.com request_id=624ca87a-b237-4a16-9e74-ad086c776d2a fwd="31.13.115.11" dyno=web.1 connect=0ms service=514ms status=200 bytes=161 protocol=https
2018-08-19T12:21:55.013052+00:00 app[web.1]: 10.127.18.55 - - [19/Aug/2018:12:21:55 +0000] "POST /webhook HTTP/1.1" 200 2 "-" "facebookexternalua"
2018-08-19T12:21:55.012197+00:00 heroku[router]: at=info method=POST path="/webhook" host=some-app.herokuapp.com request_id=032fef2b-5029-4a7b-903c-45b685b0a9ef fwd="31.13.115.2" dyno=web.1 connect=0ms service=464ms status=200 bytes=161 protocol=https
2018-08-19T12:21:56.138658+00:00 app[web.1]: 10.10.128.18 - - [19/Aug/2018:12:21:56 +0000] "POST /webhook HTTP/1.1" 200 2 "-" "facebookexternalua"
2018-08-19T12:21:56.137932+00:00 heroku[router]: at=info method=POST path="/webhook" host=some-app.herokuapp.com request_id=7f32d132-5587-4cfb-9dd4-b44ddeb8b684 fwd="31.13.115.13" dyno=web.1 connect=0ms service=734ms status=200 bytes=161 protocol=https
In fact, I would like to know what are the times of the type "service = 734ms"
Thanks in advance
service might be the time in milliseconds, in between receiving the request and serving the response; measured at the router and not the web dyno, where the request is being forwarded to.
Heroku's documentation for their router log format is here. Here's what they say about "service":
amount of time in milliseconds spent proxying data between the backend web process and the client
In other words, it's the amount of time it's taking your app (the backend web process) to process the request.

Code is working locally but not on Heroku

I am testing Facebook Messenger bot. Part of the code with core functionality:
const schedule = require('node-schedule');
app.post('/webhook/', function(req, res) {
let messaging_events = req.body.entry[0].messaging
var j = schedule.scheduleJob('10 * * * * *', function(){
for (let i = 0; i < messaging_events.length; i++) {
let event = messaging_events[i]
let sender = event.sender.id
if (event.message && event.message.text) {
let text = event.message.text
sendText(sender, "Text echo: " + text.substring(0, 100))
}
}
res.sendStatus(200)
})
})
It should reply the same message that is sent to the bot every minute (when the clock crosses 10 seconds - 2:46:10 PM, 2:47:10 PM, etc.)
If I try similar code locally, it works. It does not on Heroku. It behaves irregularly - sometimes it replies the message 2 to 4 times at once and then crashes, sometimes it does not reply anything at all. Here is the Heroku log:
2018-03-19T13:48:43.574712+00:00 heroku[web.1]: Unidling
2018-03-19T13:48:43.575153+00:00 heroku[web.1]: State changed from down to starting
2018-03-19T13:48:45.854373+00:00 heroku[web.1]: Starting process with command `node index.js`
2018-03-19T13:48:48.046370+00:00 app[web.1]: running: port
2018-03-19T13:48:48.550571+00:00 heroku[web.1]: State changed from starting to up
2018-03-19T13:49:10.035608+00:00 heroku[router]: at=info method=POST path="/webhook/" host=dry-badlands-96368.herokuapp.com request_id=89a76e53-663d-4086-8457-64c0f26be8c7 fwd="31.13.113.20" dyno=web.1 connect=1ms service=11963ms status=200 bytes=201 protocol=https
2018-03-19T13:49:10.046345+00:00 heroku[router]: at=info method=POST path="/webhook/" host=dry-badlands-96368.herokuapp.com request_id=0da8c7a9-4d5f-45bc-8797-54f608968581 fwd="31.13.105.114" dyno=web.1 connect=0ms service=20401ms status=200 bytes=201 protocol=https
2018-03-19T13:49:41.297748+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/webhook/" host=dry-badlands-96368.herokuapp.com request_id=cd1568a1-68c3-455f-872e-260f8023d925 fwd="31.13.113.170" dyno=web.1 connect=1ms service=30002ms status=503 bytes=0 protocol=https
2018-03-19T13:49:41.747709+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/webhook/" host=dry-badlands-96368.herokuapp.com request_id=32947747-1c2b-475c-a2b8-46477e13c4a2 fwd="31.13.114.116" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2018-03-19T13:50:10.059682+00:00 app[web.1]: _http_outgoing.js:491
2018-03-19T13:50:10.059738+00:00 app[web.1]: throw new Error('Can\'t set headers after they are sent.');
2018-03-19T13:50:10.059740+00:00 app[web.1]: ^
2018-03-19T13:50:10.059742+00:00 app[web.1]:
2018-03-19T13:50:10.059744+00:00 app[web.1]: Error: Can't set headers after they are sent.
2018-03-19T13:50:10.059745+00:00 app[web.1]: at validateHeader (_http_outgoing.js:491:11)
2018-03-19T13:50:10.059747+00:00 app[web.1]: at ServerResponse.setHeader (_http_outgoing.js:498:3)
2018-03-19T13:50:10.059748+00:00 app[web.1]: at ServerResponse.header (/app/node_modules/express/lib/response.js:767:10)
2018-03-19T13:50:10.059750+00:00 app[web.1]: at ServerResponse.contentType (/app/node_modules/express/lib/response.js:595:15)
2018-03-19T13:50:10.059752+00:00 app[web.1]: at ServerResponse.sendStatus (/app/node_modules/express/lib/response.js:357:8)
2018-03-19T13:50:10.059753+00:00 app[web.1]: at Job.job (/app/index.js:46:9)
2018-03-19T13:50:10.059755+00:00 app[web.1]: at Job.invoke (/app/node_modules/node-schedule/lib/schedule.js:173:10)
2018-03-19T13:50:10.059756+00:00 app[web.1]: at /app/node_modules/node-schedule/lib/schedule.js:543:11
2018-03-19T13:50:10.059758+00:00 app[web.1]: at Timeout._onTimeout (/app/node_modules/node-schedule/lib/schedule.js:501:7)
2018-03-19T13:50:10.059759+00:00 app[web.1]: at ontimeout (timers.js:482:11)
2018-03-19T13:50:10.130605+00:00 heroku[web.1]: Process exited with status 1
2018-03-19T13:50:10.241686+00:00 heroku[web.1]: State changed from up to crashed
Does anyone have any idea why is this happening? Maybe Heroku is not suited for this?
Thank you for all suggestions.

heroku request timeout parse

I migrated my app to heroku + mlab from parse. I would too often get request timeout error on the logs. I turned on verbose and below is what i get when a timeout happens:
2016-05-25T15:27:40.946050+00:00 app[web.1]: [36mverbose[39m: POST /parse/events/AppOpened { host: 'dairy-oneandahalf.herokuapp.com',
2016-05-25T15:27:40.946067+00:00 app[web.1]: connection: 'close',
2016-05-25T15:27:40.946074+00:00 app[web.1]: 'x-parse-app-build-version': '1',
2016-05-25T15:27:40.946084+00:00 app[web.1]: "__type": "Date"
2016-05-25T15:27:41.517425+00:00 app[web.1]: [36mverbose[39m: GET /parse/classes/_User { host: 'dairy-oneandahalf.herokuapp.com',
2016-05-25T15:27:41.517436+00:00 app[web.1]: connection: 'close',
2016-05-25T15:27:41.517445+00:00 app[web.1]: 'x-parse-client-version': 'i1.13.0',
2016-05-25T15:27:41.517448+00:00 app[web.1]: 'x-forwarded-for': '58.152.243.212',
2016-05-25T15:27:40.948269+00:00 heroku[router]: at=info method=POST path="/parse/events/AppOpened" host=dairy-oneandahalf.herokuapp.com request_id=3e9b1390-a1b8-487b-8229-f4c44777b2a4 fwd="58.152.243.212" dyno=web.1 connect=2ms service=6ms status=200 bytes=483
2016-05-25T15:28:12.746545+00:00 app[web.1]: [36mverbose[39m: GET /parse/classes/allPosts { host: 'dairy-oneandahalf.herokuapp.com',
2016-05-25T15:28:12.746591+00:00 app[web.1]: connection: 'close',
2016-05-25T15:28:12.746600+00:00 app[web.1]: 'x-request-id': '84c7c271-4725-42c2-a111-3cf8e2c16d52',
2016-05-25T15:28:12.746602+00:00 app[web.1]: 'total-route-time': '0',
2016-05-25T15:28:12.746605+00:00 app[web.1]: "query": {
2016-05-25T15:28:11.513492+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/parse/classes/_User" host=dairy-oneandahalf.herokuapp.com request_id=1260ec0f-3cee-4c43-a87e-9146ef154e29 fwd="58.152.243.212" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
I'm very new to heroku, can somebody explain to me what is wrong and what I can do about solving it? any help will be greatly appreciated, thanks in advance

Resources