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

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

Closed
ThomasHalwax opened this issue Nov 20, 2021 · 1 comment
Closed

Comments

@ThomasHalwax
Copy link

ThomasHalwax commented Nov 20, 2021

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
@ThomasHalwax
Copy link
Author

Looks like this is related to #2472

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

No branches or pull requests

1 participant