Skip to content

remaining timer prevents termination of the process after stopClient() #2031

Closed
@ThomasHalwax

Description

@ThomasHalwax

I made a small CLI with NodeJS to play around with Matrix. After the call of stopClient() it looks like a timer remains in the event loop which prevents the termination of the process - at least for approximately two minutes.

const sdk = require('matrix-js-sdk')
const wtf = require('wtfnode')
require ('dotenv').config()

process.once('exit', () => {
  console.log(`## event loop is empty, exiting at ${Date.now()}`)
})

const client = sdk.createClient({
  baseUrl: process.env.MATRIX_BASE_URL,
  userId: process.env.MATRIX_USER_ID,
  accessToken: process.env.MATRIX_ACCESS_TOKEN
})

const performActions = async (state) => {
  if (state !== 'PREPARED') return

  const rooms = await client.getRooms()
  console.log(`## You're member of ${rooms.length} rooms`)

  client.off('sync', performActions)  
  client.stopClient()

  console.log(`## after stopClient() at ${Date.now()}`)

  // looks like there is still an active timer
  // runCallbacks @ node_modules/matrix-js-sdk/lib/realtime-callbacks.js:146
  wtf.dump()
}


const main = async () => {
  client.on('sync', performActions)
  await client.startClient()
}

main()

Expected behavior

I expected the process to terminate immediately.

Output

❯ node src/demo.js
Getting saved sync token...
Getting push rules...
Got saved sync token
Getting saved sync...
Got reply from saved sync, exists? false
Got push rules
Checking lazy load status...
Checking whether lazy loading has changed in store...
Storing client options...
Stored client options
Getting filter...
Sending first sync request...
Waiting for saved sync before starting sync processing...
## You're member of 12 rooms
stopping MatrixClient
SyncApi.stop
## after stopClient() at 1637434044631
[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 1 (tty) (stdio)
  - fd 2 (tty) (stdio)
- Sockets:
  - 127.0.0.1:60207 -> 127.0.0.1:8008
- Timers:
  - (1000 ~ 1000 ms) runCallbacks @ /Users/thomas/Development/cli/node_modules/matrix-js-sdk/lib/realtime-callbacks.js:146
Sync no longer running: exiting
## event loop is empty, exiting at 1637434154635

Environment

  • OS: OSX
  • NodeJS: v14.18.1
  • matrix-js-sdk: 15.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions