moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

my mosca always EADDRINUSE 127.0.0.1:1883,help me! #702

Closed foooooouny closed 6 years ago

foooooouny commented 6 years ago

my Configuration in there


const ascoltatore = {
type: 'redis',
redis: require('redis'),
db: 0,
port: 6379,
password: null,
return_buffers: true, // to handle binary payloads
host: 'localhost',
// 指定数据保留多长时间,单位毫秒
ttl: {
// TTL for subscriptions
subscriptions: 60 * 1000,
// TTL for packets
packets: 60 * 1000,
},
};
const settings = {
backend: ascoltatore,
// 设置WebSocket参数
persistence: {
factory: mosca.persistence.Redis,
},
port: 1883,
host: 'localhost',  // if not this,Error message will be: EADDRINUSE null:1883
};

// init mosca mqtt const server = new mosca.Server(settings);

> server error message 
```sh
2017-11-16 21:09:07,499 ERROR 38929 nodejs.EADDRINUSEError: bind EADDRINUSE 127.0.0.1:1883 (uncaughtException throw 2 times on pid:38929)
    at Object._errnoException (util.js:1041:11)
    at _exceptionWithHostPort (util.js:1064:20)
    at listenOnMasterHandle (net.js:1402:16)
    at rr (internal/cluster/child.js:111:12)
    at Worker.send (internal/cluster/child.js:78:7)
    at process.onInternalMessage (internal/cluster/utils.js:42:8)
    at emitTwo (events.js:130:20)
    at process.emit (events.js:213:7)
    at emit (internal/child_process.js:774:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'EADDRINUSE'
errno: 'EADDRINUSE'
syscall: 'bind'
address: '127.0.0.1'
port: 1883
name: 'EADDRINUSEError'
pid: 38929
hostname: zzboydeMBP

My local Mosca boker is running,and not other Service process used 1883 port.Just local boker.If I killer it,the same problem will arise. but! Mosca events of 'ready' always is ok.

when my server start, lsof -i :1883:

COMMAND     PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google     1094 zzboy   87u  IPv4 0x9b04466011ad8add      0t0  TCP localhost:63346->localhost:ibm-mqisdp (ESTABLISHED)
node      38988 zzboy   31u  IPv4 0x9b044660038daebd      0t0  TCP localhost:ibm-mqisdp (LISTEN)
node      38988 zzboy   32u  IPv4 0x9b04466005c82add      0t0  TCP localhost:ibm-mqisdp->localhost:63346 (ESTABLISHED)

server end, lsof -i :1883:

is none

please help me,Thx very much!!!

mcollina commented 6 years ago

You have something running on your system on port 1883.

foooooouny commented 6 years ago

nothing,and if I changed this port,the same problem will arise.

foooooouny commented 6 years ago

Look.

mosca is ready
2017-11-16 21:33:00,381 ERROR 39232 nodejs.unhandledExceptionError: listen EADDRINUSE 127.0.0.1:1898
    at Object._errnoException (util.js:1041:11)
    at _exceptionWithHostPort (util.js:1064:20)
    at Server.setupListenHandle [as _listen2] (net.js:1322:14)
    at listenInCluster (net.js:1370:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1492:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:100:10)
code: 'EADDRINUSE'
errno: 'EADDRINUSE'
syscall: 'listen'
address: '127.0.0.1'
port: 1898
name: 'unhandledExceptionError'
pid: 39232
hostname: zzboydeMBP
mcollina commented 6 years ago

are you using cluster?

foooooouny commented 6 years ago

yep,and my server is using egg.js

config.cluster = {
    listen: {
      port: 7004,
      hostname: '0.0.0.0',
      // path: '/var/run/egg.sock',
    },
  };
mcollina commented 6 years ago

does it work without cluster and egg?

foooooouny commented 6 years ago

eh...Have not tried.

foooooouny commented 6 years ago

if used cluster will have this question?

mcollina commented 6 years ago

I don't know really, I typically deploy this on servers with a single CPU.

foooooouny commented 6 years ago

eh.....Okey.I'm trying something else,Thx vary mush.