Skip to content

Question: How do we handle deferred promise rejections due to dropped entries? #28

@mhassan1

Description

@mhassan1

Thanks for the awesome library!

I am experimenting with the situation where Fluent becomes unreachable while events are being emitted. I believe sendQueueMaxLimit is the right way to prevent backpressure, but I noticed that dropped entries cause an unhandledPromiseRejection, and I don't see a way to catch the rejection.

Here is a simple reproduction:

const { FluentClient } = require('@fluent-org/logger')
const logger = new FluentClient('testing', {
  socket: {
    host: 'i-dont-exist.com'
  },
  sendQueueMaxLimit: {
    length: 2,
  },
  ack: {}
})

const run = async () => {
  await Promise.all(Array(3).fill().map(async (_, i) => {
    try {
      await logger.emit('label', {
        hello: i
      })
      console.log('written!', i)
    } catch (err) {
      console.error('uh oh!', err.message)
    }
  }))
}

run()

This results in unhandledPromiseRejection: DroppedError. It seems the dropEntry.deferred.reject here is not bubbled up to the caller.

The only resolution I've found is to add the following:

process.on('unhandledRejection', (reason, promise) => {
  if (reason instanceof FluentError.DroppedError) return
  throw promise
})

Is there a correct way to handle this that I am missing?

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