Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: Add option to choose between worker-timers and native timers #1806

Closed
olso-nordsec opened this issue Feb 29, 2024 · 18 comments · Fixed by #1818
Closed

[feat]: Add option to choose between worker-timers and native timers #1806

olso-nordsec opened this issue Feb 29, 2024 · 18 comments · Fixed by #1818

Comments

@olso-nordsec
Copy link
Contributor

olso-nordsec commented Feb 29, 2024

MQTTjs Version

5.3.6

Broker

rabbitmq with cowboy

Environment

Browser

Firefox 123.0, running inside MV3 browser extension (service worker -> the one without window)

Description

I think it got broken by this #1779

Our server closes the connection after 60s, because there are no pings

Then new connection is opened

Our keep alive is set to 30s

We've always used 30s

Minimal Reproduction

 this.mqttClient = mqtt.connect(credentials.endpoint, {
      log: (...args) => console.log('[mqtt]', new Date().toISOString(), ...args),
      protocolId: 'MQIsdp',
      protocolVersion: 3,
      path: '/mqtt',
      clean: true,
      resubscribe: true,
      connectTimeout: 15 * 1000,
      reconnectPeriod: 30 * 1000,
      keepalive: 30,
      transformWsUrl: (url, options): string => {
        /* eslint-disable no-param-reassign */
        options.clientId = this.credentials.ncAppUserUid;
        options.username = this.credentials.username;
        options.password = this.credentials.password;
        /* eslint-enable no-param-reassign */

        return this.credentials.endpoint;
      },
    });

Debug logs

[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.protocol wss instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.protocolVersion 3 instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.username undefined instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.keepalive 30 instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.reconnectPeriod 30000 instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.rejectUnauthorized undefined instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: options.properties.topicAliasMaximum undefined instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: clientId mqttjs_cb55d853 instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z MqttClient :: setting up stream instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z connect :: calling method to clear reconnect instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z _clearReconnect : clearing reconnect timer instrument.js:117
[mqtt] 2024-02-29T10:23:40.642Z connect :: using streamBuilder provided to client to create stream instrument.js:117
[mqtt] 2024-02-29T10:23:40.643Z connect :: pipe stream to writable stream instrument.js:117
[mqtt] 2024-02-29T10:23:40.643Z connect: sending packet `connect` instrument.js:117
[mqtt] 2024-02-29T10:23:40.643Z _writePacket :: packet: %O 
Object { cmd: "connect", protocolId: "MQIsdp", protocolVersion: 3, clean: true, clientId: "REMOVED", keepalive: 30, username: "REMOVED", password: "REMOVED", properties: undefined }
instrument.js:117
[mqtt] 2024-02-29T10:23:40.643Z _writePacket :: emitting `packetsend` instrument.js:117
[mqtt] 2024-02-29T10:23:40.643Z _writePacket :: writing to stream instrument.js:117
[mqtt] 2024-02-29T10:23:40.654Z _writePacket :: writeToStream result %s true instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: array topic %s user_logout instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: pushing topic `%s` and qos `%s` to subs list user_logout 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: array topic %s extension instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: pushing topic `%s` and qos `%s` to subs list extension 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: array topic %s extension/3.9.1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: pushing topic `%s` and qos `%s` to subs list extension/3.9.1 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: array topic %s extension/firefox instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: pushing topic `%s` and qos `%s` to subs list extension/firefox 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: array topic %s offer instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: pushing topic `%s` and qos `%s` to subs list offer 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.655Z subscribe: array topic %s content instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z subscribe: pushing topic `%s` and qos `%s` to subs list content 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z subscribe: array topic %s inapp instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z subscribe: pushing topic `%s` and qos `%s` to subs list inapp 1 instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z subscribe :: resubscribe true instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z subscribe :: call _sendPacket instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z _sendPacket :: (%s) ::  start 55b2e31f3c625aedf352918d1c2a9ab14f6293e6d625704849dd1fd149208646 instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z _sendPacket :: client not connected. Storing packet offline. instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z _storePacket :: packet: %o 
Object { cmd: "subscribe", subscriptions: (7) […], messageId: 20868 }
instrument.js:117
[mqtt] 2024-02-29T10:23:40.656Z _storePacket :: cb? %s true instrument.js:117
[mqtt] 2024-02-29T10:23:41.189Z writable stream :: parsing buffer instrument.js:117
[mqtt] 2024-02-29T10:23:41.189Z parser :: on packet push to packets array. instrument.js:117
[mqtt] 2024-02-29T10:23:41.190Z work :: getting next packet in queue instrument.js:117
[mqtt] 2024-02-29T10:23:41.190Z work :: packet pulled from queue instrument.js:117
[mqtt] 2024-02-29T10:23:41.190Z _handlePacket :: emitting packetreceive instrument.js:117
[mqtt] 2024-02-29T10:23:41.190Z _handleConnack instrument.js:117
[mqtt] 2024-02-29T10:23:41.190Z _setupPingTimer :: keepalive %d (seconds) 30 instrument.js:117
[mqtt] 2024-02-29T10:23:41.191Z connect :: sending queued packets instrument.js:117
[mqtt] 2024-02-29T10:23:41.191Z deliver :: entry %o 
Object { packet: {…}, cb: BoundFunctionObject }
instrument.js:117
[mqtt] 2024-02-29T10:23:41.192Z deliver :: call _sendPacket for %o 
Object { cmd: "subscribe", subscriptions: (7) […], messageId: 20868 }
instrument.js:117
[mqtt] 2024-02-29T10:23:41.192Z _sendPacket :: (%s) ::  start 55b2e31f3c625aedf352918d1c2a9ab14f6293e6d625704849dd1fd149208646 instrument.js:117
[mqtt] 2024-02-29T10:23:41.192Z _writePacket :: packet: %O 
Object { cmd: "subscribe", subscriptions: (7) […], messageId: 20868 }
instrument.js:117
[mqtt] 2024-02-29T10:23:41.192Z _writePacket :: emitting `packetsend` instrument.js:117
[mqtt] 2024-02-29T10:23:41.192Z _writePacket :: writing to stream instrument.js:117
[mqtt] 2024-02-29T10:23:41.193Z _writePacket :: writeToStream result %s false instrument.js:117
[mqtt] 2024-02-29T10:23:41.193Z _writePacket :: handle events on `drain` once through callback. instrument.js:117
[mqtt] 2024-02-29T10:23:41.194Z noop :: undefined instrument.js:117
[mqtt] 2024-02-29T10:23:41.195Z deliver :: entry %o undefined instrument.js:117
[mqtt] 2024-02-29T10:23:41.195Z _resubscribe instrument.js:117
[mqtt] 2024-02-29T10:23:41.326Z writable stream :: parsing buffer instrument.js:117
[mqtt] 2024-02-29T10:23:41.327Z parser :: on packet push to packets array. instrument.js:117
[mqtt] 2024-02-29T10:23:41.327Z work :: getting next packet in queue instrument.js:117
[mqtt] 2024-02-29T10:23:41.327Z work :: packet pulled from queue instrument.js:117
[mqtt] 2024-02-29T10:23:41.327Z _handlePacket :: emitting packetreceive instrument.js:117
[mqtt] 2024-02-29T10:23:41.327Z _handleAck :: packet type suback instrument.js:117
[mqtt] 2024-02-29T10:24:48.750Z (%s)stream :: on close 55b2e31f3c625aedf352918d1c2a9ab14f6293e6d625704849dd1fd149208646 instrument.js:117
[mqtt] 2024-02-29T10:24:48.751Z _flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function instrument.js:117
[mqtt] 2024-02-29T10:24:48.751Z stream: emit close to MqttClient instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z close :: connected set to `false` instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z close :: clearing connackTimer instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z close :: clearing ping timer instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z close :: calling _setupReconnect instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z _setupReconnect :: emit `offline` state instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z _setupReconnect :: set `reconnecting` to `true` instrument.js:117
[mqtt] 2024-02-29T10:24:48.752Z _setupReconnect :: setting reconnectTimer for %d ms 30000 instrument.js:117
[mqtt] 2024-02-29T10:25:18.756Z reconnectTimer :: reconnect triggered! instrument.js:117
[mqtt] 2024-02-29T10:25:18.763Z _reconnect: emitting reconnect to client instrument.js:117
[mqtt] 2024-02-29T10:25:18.766Z _reconnect: calling connect instrument.js:117
[mqtt] 2024-02-29T10:25:18.767Z connect :: calling method to clear reconnect instrument.js:117
[mqtt] 2024-02-29T10:25:18.767Z _clearReconnect : clearing reconnect timer instrument.js:117
[mqtt] 2024-02-29T10:25:18.767Z connect :: using streamBuilder provided to client to create stream instrument.js:117
[mqtt] 2024-02-29T10:25:18.768Z connect :: pipe stream to writable stream instrument.js:117
[mqtt] 2024-02-29T10:25:18.768Z connect: sending packet `connect` instrument.js:117
[mqtt] 2024-02-29T10:25:18.768Z _writePacket :: packet: %O 
Object { cmd: "connect", protocolId: "MQIsdp", protocolVersion: 3, clean: true, clientId: "REMOVED", keepalive: 30, username: "REMOVED", password: "REMOVED", properties: undefined }
instrument.js:117
[mqtt] 2024-02-29T10:25:18.769Z _writePacket :: emitting `packetsend` instrument.js:117
[mqtt] 2024-02-29T10:25:18.769Z _writePacket :: writing to stream instrument.js:117
[mqtt] 2024-02-29T10:25:18.769Z _writePacket :: writeToStream result %s true instrument.js:117
[mqtt] 2024-02-29T10:25:19.642Z writable stream :: parsing buffer instrument.js:117
[mqtt] 2024-02-29T10:25:19.642Z parser :: on packet push to packets array. instrument.js:117
[mqtt] 2024-02-29T10:25:19.642Z work :: getting next packet in queue instrument.js:117
[mqtt] 2024-02-29T10:25:19.643Z work :: packet pulled from queue instrument.js:117
[mqtt] 2024-02-29T10:25:19.643Z _handlePacket :: emitting packetreceive instrument.js:117
[mqtt] 2024-02-29T10:25:19.643Z _handleConnack instrument.js:117
[mqtt] 2024-02-29T10:25:19.643Z _setupPingTimer :: keepalive %d (seconds) 30 instrument.js:117
[mqtt] 2024-02-29T10:25:19.644Z connect :: sending queued packets instrument.js:117
[mqtt] 2024-02-29T10:25:19.644Z deliver :: entry %o undefined instrument.js:117
[mqtt] 2024-02-29T10:25:19.644Z _resubscribe instrument.js:117
[mqtt] 2024-02-29T10:25:19.644Z subscribe: object topic %s, %o user_logout 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: pushing topic `%s` and qos `%s` to subs list user_logout 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: object topic %s, %o extension 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: pushing topic `%s` and qos `%s` to subs list extension 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: object topic %s, %o extension/3.9.1 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: pushing topic `%s` and qos `%s` to subs list extension/3.9.1 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: object topic %s, %o extension/firefox 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: pushing topic `%s` and qos `%s` to subs list extension/firefox 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.645Z subscribe: object topic %s, %o offer 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe: pushing topic `%s` and qos `%s` to subs list offer 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe: object topic %s, %o content 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe: pushing topic `%s` and qos `%s` to subs list content 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe: object topic %s, %o inapp 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe: pushing topic `%s` and qos `%s` to subs list inapp 1 instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe :: resubscribe true instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z subscribe :: call _sendPacket instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z _sendPacket :: (%s) ::  start 55b2e31f3c625aedf352918d1c2a9ab14f6293e6d625704849dd1fd149208646 instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z _writePacket :: packet: %O 
Object { cmd: "subscribe", subscriptions: (7) […], messageId: 20869 }
instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z _writePacket :: emitting `packetsend` instrument.js:117
[mqtt] 2024-02-29T10:25:19.646Z _writePacket :: writing to stream instrument.js:117
[mqtt] 2024-02-29T10:25:19.647Z _writePacket :: writeToStream result %s false instrument.js:117
[mqtt] 2024-02-29T10:25:19.647Z _writePacket :: invoking cb instrument.js:117
[mqtt] 2024-02-29T10:25:19.647Z noop :: undefined instrument.js:117
[mqtt] 2024-02-29T10:25:19.803Z writable stream :: parsing buffer instrument.js:117
[mqtt] 2024-02-29T10:25:19.804Z parser :: on packet push to packets array. instrument.js:117
[mqtt] 2024-02-29T10:25:19.804Z work :: getting next packet in queue instrument.js:117
[mqtt] 2024-02-29T10:25:19.804Z work :: packet pulled from queue instrument.js:117
[mqtt] 2024-02-29T10:25:19.804Z _handlePacket :: emitting packetreceive instrument.js:117
[mqtt] 2024-02-29T10:25:19.804Z _handleAck :: packet type suback instrument.js:117
[mqtt] 2024-02-29T10:25:19.804Z noop :: null instrument.js:117
[mqtt] 2024-02-29T10:26:27.150Z (%s)stream :: on close 55b2e31f3c625aedf352918d1c2a9ab14f6293e6d625704849dd1fd149208646 instrument.js:117
[mqtt] 2024-02-29T10:26:27.157Z _flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function instrument.js:117
[mqtt] 2024-02-29T10:26:27.157Z stream: emit close to MqttClient instrument.js:117
[mqtt] 2024-02-29T10:26:27.158Z close :: connected set to `false` instrument.js:117
[mqtt] 2024-02-29T10:26:27.159Z close :: clearing connackTimer instrument.js:117
[mqtt] 2024-02-29T10:26:27.159Z close :: clearing ping timer instrument.js:117
[mqtt] 2024-02-29T10:26:27.159Z close :: calling _setupReconnect instrument.js:117
[mqtt] 2024-02-29T10:26:27.159Z _setupReconnect :: emit `offline` state instrument.js:117
[mqtt] 2024-02-29T10:26:27.159Z _setupReconnect :: set `reconnecting` to `true` instrument.js:117
[mqtt] 2024-02-29T10:26:27.160Z _setupReconnect :: setting reconnectTimer for %d ms 30000 instrument.js:117
[mqtt] 2024-02-29T10:26:57.166Z reconnectTimer :: reconnect triggered! instrument.js:117
[mqtt] 2024-02-29T10:26:57.167Z _reconnect: emitting reconnect to client instrument.js:117
[mqtt] 2024-02-29T10:26:57.175Z _reconnect: calling connect instrument.js:117
[mqtt] 2024-02-29T10:26:57.178Z connect :: calling method to clear reconnect instrument.js:117
[mqtt] 2024-02-29T10:26:57.179Z _clearReconnect : clearing reconnect timer instrument.js:117
[mqtt] 2024-02-29T10:26:57.180Z connect :: using streamBuilder provided to client to create stream instrument.js:117
[mqtt] 2024-02-29T10:26:57.182Z connect :: pipe stream to writable stream instrument.js:117
[mqtt] 2024-02-29T10:26:57.183Z connect: sending packet `connect` instrument.js:117
[mqtt] 2024-02-29T10:26:57.183Z _writePacket :: packet: %O 
Object { cmd: "connect", protocolId: "MQIsdp", protocolVersion: 3, clean: true, clientId: "REMOVED", keepalive: 30, username: "REMOVED", password: "REMOVED", properties: undefined }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.184Z _writePacket :: emitting `packetsend` instrument.js:117
[mqtt] 2024-02-29T10:26:57.190Z _writePacket :: writing to stream instrument.js:117
[mqtt] 2024-02-29T10:26:57.193Z _writePacket :: writeToStream result %s true instrument.js:117
[mqtt] 2024-02-29T10:26:57.759Z writable stream :: parsing buffer instrument.js:117
[mqtt] 2024-02-29T10:26:57.760Z parser :: on packet push to packets array. instrument.js:117
[mqtt] 2024-02-29T10:26:57.760Z work :: getting next packet in queue instrument.js:117
[mqtt] 2024-02-29T10:26:57.760Z work :: packet pulled from queue instrument.js:117
[mqtt] 2024-02-29T10:26:57.760Z _handlePacket :: emitting packetreceive instrument.js:117
[mqtt] 2024-02-29T10:26:57.760Z _handleConnack instrument.js:117
[mqtt] 2024-02-29T10:26:57.760Z _setupPingTimer :: keepalive %d (seconds) 30 instrument.js:117
[mqtt] 2024-02-29T10:26:57.762Z connect :: sending queued packets instrument.js:117
[mqtt] 2024-02-29T10:26:57.762Z deliver :: entry %o undefined instrument.js:117
[mqtt] 2024-02-29T10:26:57.762Z _resubscribe instrument.js:117
[mqtt] 2024-02-29T10:26:57.762Z subscribe: object topic %s, %o user_logout 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.762Z subscribe: pushing topic `%s` and qos `%s` to subs list user_logout 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: object topic %s, %o extension 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: pushing topic `%s` and qos `%s` to subs list extension 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: object topic %s, %o extension/3.9.1 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: pushing topic `%s` and qos `%s` to subs list extension/3.9.1 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: object topic %s, %o extension/firefox 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: pushing topic `%s` and qos `%s` to subs list extension/firefox 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: object topic %s, %o offer 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: pushing topic `%s` and qos `%s` to subs list offer 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: object topic %s, %o content 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: pushing topic `%s` and qos `%s` to subs list content 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.763Z subscribe: object topic %s, %o inapp 
Object { qos: 1 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z subscribe: pushing topic `%s` and qos `%s` to subs list inapp 1 instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z subscribe :: resubscribe true instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z subscribe :: call _sendPacket instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z _sendPacket :: (%s) ::  start 55b2e31f3c625aedf352918d1c2a9ab14f6293e6d625704849dd1fd149208646 instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z _writePacket :: packet: %O 
Object { cmd: "subscribe", subscriptions: (7) […], messageId: 20870 }
instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z _writePacket :: emitting `packetsend` instrument.js:117
[mqtt] 2024-02-29T10:26:57.764Z _writePacket :: writing to stream instrument.js:117
[mqtt] 2024-02-29T10:26:57.765Z _writePacket :: writeToStream result %s false instrument.js:117
[mqtt] 2024-02-29T10:26:57.765Z _writePacket :: invoking cb instrument.js:117
[mqtt] 2024-02-29T10:26:57.765Z noop :: undefined instrument.js:117
[mqtt] 2024-02-29T10:26:57.913Z writable stream :: parsing buffer instrument.js:117
[mqtt] 2024-02-29T10:26:57.914Z parser :: on packet push to packets array. instrument.js:117
[mqtt] 2024-02-29T10:26:57.914Z work :: getting next packet in queue instrument.js:117
[mqtt] 2024-02-29T10:26:57.914Z work :: packet pulled from queue instrument.js:117
[mqtt] 2024-02-29T10:26:57.914Z _handlePacket :: emitting packetreceive instrument.js:117
[mqtt] 2024-02-29T10:26:57.914Z _handleAck :: packet type suback instrument.js:117
[mqtt] 2024-02-29T10:26:57.914Z noop :: null instrument.js:117
@robertsLando
Copy link
Member

@olso-nordsec Wondering if webworkers do have support for setTimeout and clearTimeout ?

@olso-nordsec
Copy link
Contributor Author

olso-nordsec commented Feb 29, 2024

@robertsLando yea, they work

i can't fully understand the log, but you are not seeing any pings right?

@robertsLando
Copy link
Member

robertsLando commented Feb 29, 2024

@olso-nordsec I tested it in my webworker tests and it's working well, see #1807 . I think there might be some issues in your worker setup maybe? How do you spawn your web worker?

@robertsLando robertsLando changed the title [Bug]: Keep alive no longer being sent [Bug]: Keep alive no longer being sent on web workers Feb 29, 2024
@olso-nordsec
Copy link
Contributor Author

btw, this is happening on firefox only

there is not concept of "spawn", since that is handled by browser (this is hapenning in mv3 browser extension)

maybe if you point me to specific places, i can add breakpoints and see whats up

@robertsLando
Copy link
Member

robertsLando commented Feb 29, 2024

client.pingTimer handles the ping to broker (check PingTimer class) to keep the client alive, it calls client._checkPing function every keepalive seconds. If you want you could also setup your own ping timer to see if that works (manually call client._checkPing every keepalive milliseconds and stop it if you get a ''Keepalive timeout" error).

BTW the tests runs on FIrefox/Chrome and Webkit (safari) so maybe it's the firefox version the problem

@olso-nordsec
Copy link
Contributor Author

Screenshot 2024-03-01 at 09 40 25

found the culprit isWebWorker is

  • true in chrome
  • false in firefox

@robertsLando
Copy link
Member

robertsLando commented Mar 1, 2024

I thought about that but in that case you should get an error on worker as it would try to use worker timers and that's not allowed inside a worker. Could you tell me how to correctly identify web worker in firefox, at least on your firefox version?

@robertsLando
Copy link
Member

@olso-nordsec News on this?

@olso-nordsec
Copy link
Contributor Author

olso-nordsec commented Mar 5, 2024

it would be extension specific code tho, afaik, there is no other clear way to detect it in MV3 firefox

i'm thinking maybe it could be a config option?

@robertsLando
Copy link
Member

it would be extension specific code tho, afaik, there is no other clear way to detect it in MV3 firefox

What do you mean with extension specific code?

@olso-nordsec
Copy link
Contributor Author

For example, in firefox, checking if globalThis.browser.runtime is defined

@robertsLando
Copy link
Member

Is there any related doc?

@olso-nordsec
Copy link
Contributor Author

olso-nordsec commented Mar 5, 2024

Sorry there are no official docs on this, and also its a very bad time, because docs are being rewritten from MV2 to MV3, but I had a look around github

https://github.com/fregante/webext-detect-page/blob/main/index.ts

this one seems to have pretty good detection (even false positives on firefox)

but i would understand if you wouldnt want to include this monstrosity in your codebase or as a dependency

thats why i suggest a config option that would get passed down to PingTimer

@robertsLando
Copy link
Member

thats why i suggest a config option that would get passed down to PingTimer

Oh ok now that's more clear what you meant. I can do that :)

@robertsLando robertsLando removed the bug label Mar 5, 2024
@robertsLando robertsLando changed the title [Bug]: Keep alive no longer being sent on web workers [feat]: Add option to choose between worker-timers or native timers Mar 5, 2024
@robertsLando robertsLando changed the title [feat]: Add option to choose between worker-timers or native timers [feat]: Add option to choose between worker-timers and native timers Mar 5, 2024
@olso-nordsec
Copy link
Contributor Author

olso-nordsec commented Mar 14, 2024

hey @robertsLando
have you started working on this? if not, i can maybe make PR myself, wdyt?

@robertsLando
Copy link
Member

@olso-nordsec not yet, sorry! Feel free to open a PR 🙏🏻 also remember to add a test

@olso-nordsec
Copy link
Contributor Author

@robertsLando i've tried running test on fresh clone, and im getting these

    ✖ connect should throw error
      'test did not finish before its parent and was cancelled'

    ✖ publish should throw error
      'test did not finish before its parent and was cancelled'

  ▶ async methods

    'test did not finish before its parent and was cancelled'

▶ MqttClient (1634.075125ms)

  Error: read ECONNRESET
      at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
    errno: -54,
    code: 'ECONNRESET',
    syscall: 'read'
  }

@robertsLando
Copy link
Member

@olso-nordsec Tests are a bit flaky and I sitll don't understand why, they just fail for no reason sometimes, ignore them for now

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

Successfully merging a pull request may close this issue.

2 participants