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

onSocketClose option cannot be used with ThreadStream (multistream) #77

Closed
ggrossetie opened this issue Jul 24, 2022 · 5 comments
Closed

Comments

@ggrossetie
Copy link
Contributor

Given the following code:

const pino = require('pino')

const tcpStream = pino.transport({
  level: "info",
  target: "pino-socket",
  options: {
    address: "localhost",
    port: "13370",
    mode: "tcp",
    reconnect: true,
    onSocketClose: () => { console.log('') }
  }
})

tcpStream.on('error', () => { /* ignore */ })
const pinoStreams = [
  {
    level: "debug",
    stream: pino.transport({
      target: "pino/file"
    })
  },
  {
    stream: tcpStream
  }
]

const logger = pino({
  level: "info",
}, pino.multistream(pinoStreams))

logger.info("Keep alive!")

The following exception is thrown:

    this[kPort].postMessage({
                ^

DOMException [DataCloneError]: () => { console.log('') } could not be cloned.
    at new Worker (node:internal/worker:235:17)
    at createWorker (/path/to/project/node_modules/thread-stream/index.js:50:18)
    at new ThreadStream (/path/to/project/node_modules/thread-stream/index.js:209:19)
    at buildStream (/path/to/project/node_modules/pino/lib/transport.js:21:18)
    at Function.transport (/path/to/project/node_modules/pino/lib/transport.js:110:10)
    at Object.<anonymous> (/path/to/project/index.js:3:25)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
@mcollina
Copy link
Member

That's expected. Functions cannot be serialized across worker thread boundaries. You'll need to use the programmatic API and create your own transport that reuse this one if you want to use that.

1 similar comment
@mcollina
Copy link
Member

That's expected. Functions cannot be serialized across worker thread boundaries. You'll need to use the programmatic API and create your own transport that reuse this one if you want to use that.

@ggrossetie
Copy link
Contributor Author

I think we should add a note in the documentation.

You'll need to use the programmatic API and create your own transport that reuse this one if you want to use that.

Do we already have some documentation on how to proceed?

@ggrossetie
Copy link
Contributor Author

@mcollina Maybe we should emit an event socketClose instead of defining a callback. It's more portable, what do you think?

@mcollina
Copy link
Member

go for it, keep the callback too

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

2 participants