게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
[heroku]node socket.io client가 연결 유지 안됨
게시물ID : programmer_10853짧은주소 복사하기
작성자 : Believer
추천 : 0
조회수 : 2194회
댓글수 : 5개
등록시간 : 2015/06/04 20:42:56
옵션
  • 본인삭제금지
node-socket.io를 사용해서 간단한 메세지 한개를 만들었습니다.

로컬의 노드서버, mysql 에서 제 프로그램을 실행할 때는
소켓io 클라이언트(브라우저)를 한참 방치해도 연결이 끉어지지 않았는데

heroku라는 서비스를 발견해서 같은 소스를 올려 동작시켰는데 (물론 서버주소와 db주소는 바뀌었음)
클라이언트의 연결이 일정 시간 방치시 끉어지네요.

연결이 끉어질 때 브라우저 콘솔에는
Uncaught TypeError: Cannot read property 'apply' of undefined
  1. 3.Manager.emitAll @ socket.io.js:169
    (anonymous function) @ socket.io.js:558

  2. 169|     this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
    558|     self.emitAll('reconnect_attempt', self.backoff.attempts);
라고 나오네요. 아마 재접속이 안된다는 말인..거 같긴한데 잘 모르겠습니다.

그냥 클라이언트만 끉어지면 그나마 감사하겠지만 서버도 함께 멈춰줍니다 ;;

다음은 heroku logs 내용입니다.

2015-06-04T11:16:58.105477+00:00 heroku[web.1]: State changed from crashed to starting
2015-06-04T11:17:00.204512+00:00 heroku[web.1]: Starting process with command `node index.js`
2015-06-04T11:17:02.276879+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-06-04T11:17:02.276856+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-06-04T11:17:03.875109+00:00 heroku[web.1]: State changed from starting to up
2015-06-04T11:17:05.275511+00:00 heroku[router]: at=info method=GET path="/" host=rocky-basin-3981.herokuapp.com request_id=c8004c67-8e32-4c4b-8976-8831c0bee368 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=24ms status=200 bytes=31612
2015-06-04T11:17:05.749416+00:00 heroku[router]: at=info method=GET path="/socket.io/socket.io.js" host=rocky-basin-3981.herokuapp.com request_id=01fe0a3e-5ca1-4144-a2ff-351b48290e2c fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=2ms service=5ms status=304 bytes=85
2015-06-04T11:17:05.770545+00:00 heroku[router]: at=info method=GET path="/images/desktop/bg_gaussian55.jpg" host=rocky-basin-3981.herokuapp.com request_id=d60cc8f4-28b6-4a86-9aad-e8aad501b07c fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=6ms status=304 bytes=237
2015-06-04T11:17:05.763083+00:00 heroku[router]: at=info method=GET path="/images/desktop/bg_normal.jpg" host=rocky-basin-3981.herokuapp.com request_id=4eacb399-bad3-488d-8a03-42e5b2654cfd fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=3ms service=9ms status=304 bytes=238
2015-06-04T11:17:05.769827+00:00 heroku[router]: at=info method=GET path="/images/taskbar/task_view.png" host=rocky-basin-3981.herokuapp.com request_id=4695edb7-82cf-48e9-8970-898dcdd38535 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=3ms status=304 bytes=234
2015-06-04T11:17:05.768798+00:00 heroku[router]: at=info method=GET path="/images/taskbar/search.png" host=rocky-basin-3981.herokuapp.com request_id=bc035d2a-e4ff-4989-b951-6099de8670ab fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=8ms status=304 bytes=235
2015-06-04T11:17:05.775214+00:00 heroku[router]: at=info method=GET path="/images/taskbar/start_op0.png" host=rocky-basin-3981.herokuapp.com request_id=ef4af6b5-268d-4915-b29d-780e2f550d87 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=5ms service=9ms status=304 bytes=234
2015-06-04T11:17:06.058822+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1433416627819-0" host=rocky-basin-3981.herokuapp.com request_id=6f02b705-1ffb-4925-82b6-579d37109c44 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=2ms service=21ms status=200 bytes=306
2015-06-04T11:17:06.331742+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1433416628106-1&sid=t6d_42nqQnVZsWpLAAAA" host=rocky-basin-3981.herokuapp.com request_id=2c81b77e-20fe-4908-a697-3c37be9bfd0b fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=5ms status=200 bytes=208
2015-06-04T11:17:06.754888+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=1433416628515-3&sid=t6d_42nqQnVZsWpLAAAA" host=rocky-basin-3981.herokuapp.com request_id=37a3312d-40c7-49a9-8b6e-015f66f29f38 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=17ms status=200 bytes=267
2015-06-04T11:17:06.757564+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1433416628381-2&sid=t6d_42nqQnVZsWpLAAAA" host=rocky-basin-3981.herokuapp.com request_id=1a5da7c1-4cf4-4053-8c2e-4fee8848fbd1 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=2ms service=156ms status=200 bytes=402
2015-06-04T11:17:06.757954+00:00 app[web.1]: user - t6d_42nqQnVZsWpLAAAA / open app - 헹의에슐가 롑흔리나 : 네이버 블로그
2015-06-04T11:17:07.125780+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1433416628813-4&sid=t6d_42nqQnVZsWpLAAAA" host=rocky-basin-3981.herokuapp.com request_id=8019942e-33e0-4df4-8ae6-919a644d8ace fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=6ms service=84ms status=200 bytes=207
2015-06-04T11:17:07.069991+00:00 heroku[router]: at=info method=GET path="/images/window/xblack2.png" host=rocky-basin-3981.herokuapp.com request_id=538292b3-3802-4e43-b393-094e7abf2038 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=4ms service=26ms status=304 bytes=234
2015-06-04T11:17:08.752922+00:00 heroku[router]: at=info method=GET path="/images/window/xwhite.png" host=rocky-basin-3981.herokuapp.com request_id=9c207387-4017-40d4-9a99-51596767def6 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=2ms service=10ms status=304 bytes=234
2015-06-04T11:17:22.532481+00:00 heroku[router]: at=info method=GET path="/images/taskbar/task_view_hover.png" host=rocky-basin-3981.herokuapp.com request_id=66eff144-0362-4301-a17f-9434ba4ce43c fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=13ms status=200 bytes=383
2015-06-04T11:17:28.739395+00:00 heroku[router]: at=info method=GET path="/images/taskbar/start_op0_hover.png" host=rocky-basin-3981.herokuapp.com request_id=9814ab85-4c60-43e9-90fd-d48e7cf753fb fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=1ms service=13ms status=200 bytes=694
2015-06-04T11:18:13.388740+00:00 app[web.1]: events.js:85
2015-06-04T11:18:13.388746+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2015-06-04T11:18:13.388748+00:00 app[web.1]:             ^
2015-06-04T11:18:13.388750+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2015-06-04T11:18:13.388752+00:00 app[web.1]:     at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:103:13)
2015-06-04T11:18:13.388754+00:00 app[web.1]:     at Socket.emit (events.js:129:20)
2015-06-04T11:18:13.388753+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:102:28)
2015-06-04T11:18:13.388756+00:00 app[web.1]:     at _stream_readable.js:908:16
2015-06-04T11:18:13.388758+00:00 app[web.1]:     at process._tickCallback (node.js:355:11)
2015-06-04T11:18:13.402278+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket&sid=t6d_42nqQnVZsWpLAAAA" host=rocky-basin-3981.herokuapp.com request_id=0a6e07f1-156d-477e-a22a-4e8b23905798 fwd="[본삭금 아이피 삭제]" dyno=web.1 connect=4ms service=66624ms status=101 bytes=129
2015-06-04T11:18:14.328647+00:00 heroku[web.1]: Process exited with status 1
2015-06-04T11:18:16.854123+00:00 heroku[web.1]: Starting process with command `node index.js`
2015-06-04T11:18:14.348078+00:00 heroku[web.1]: State changed from up to crashed
2015-06-04T11:18:14.348968+00:00 heroku[web.1]: State changed from crashed to starting
2015-06-04T11:18:18.844058+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2015-06-04T11:18:18.844077+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2015-06-04T11:18:20.561713+00:00 heroku[web.1]: State changed from starting to up
2015-06-04T11:19:12.951849+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2015-06-04T11:19:12.951843+00:00 app[web.1]: events.js:85
2015-06-04T11:19:12.951854+00:00 app[web.1]:     at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:103:13)
2015-06-04T11:19:12.951851+00:00 app[web.1]:             ^
2015-06-04T11:19:12.951852+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2015-06-04T11:19:12.951856+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:102:28)
2015-06-04T11:19:12.951857+00:00 app[web.1]:     at Socket.emit (events.js:129:20)
2015-06-04T11:19:12.951858+00:00 app[web.1]:     at _stream_readable.js:908:16
2015-06-04T11:19:12.951860+00:00 app[web.1]:     at process._tickCallback (node.js:355:11)
2015-06-04T11:19:13.812421+00:00 heroku[web.1]: State changed from up to crashed
2015-06-04T11:19:13.796931+00:00 heroku[web.1]: Process exited with status 1
2015-06-04T11:20:51.595972+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=rocky-basin-3981.herokuapp.com request_id=fea65ef4-034f-4f4f-8fd4-23b7e9dbe7b7 fwd="[본삭금 아이피 삭제]"
 dyno= connect= service= status=503 bytes=



별거 하는 일 없는 서버코드
---------------------------
var S_PORT = process.env.PORT || 5000;
var mysql = require('mysql'),
express = require('express'),
app = express(),
server = require('http').createServer(app);
app.use(express.static(__dirname + '/public'));
var io = require('socket.io').listen(server);

var db = mysql.createConnection({
    host: process.env.DB_HOST,
    port: 3306,
    user: process.env.DB_USER,
    database: process.env.DB_NAME,
    password: process.env.DB_PASSWORD
});
db.connect(function(err){
    if (err) console.log(err)
});
server.listen(S_PORT);
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});

var findApp = function(data, callback){
var query = db.query('select * from appList where app_id = '+mysql.escape(data) ,function(err,rows){
callback(rows);
});
}
io.sockets.on('connection', function(socket){
socket.on('open app', function(data) {
findApp(data, function(row){
socket.emit('open window',row);
console.log('user -',socket.id ,'/ open app -',row[0].app_name);
});
});
}); 


클라이언트 socket.io 부분 코드
-----------------------------
var socket = io('https://rocky-basin-3981.herokuapp.com/');
var send = document.getElementById("new-window");
send.addEventListener('click', function(){
    socket.emit('open app', '2');
});
socket.on('open window',function(data) {
    createWindow(data);
});


node도 처음 heroku도 처음이라서 어디서 디버그 해야 할 지 혼란스럽네요.
로컬에선 잘 돌아갔는데 차이라면 https? 왜 소켓연결이 끉어지고 서버가 죽을까요...
출처 https://rocky-basin-3981.herokuapp.com/
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호