fastify / fastify

Fast and low overhead web framework, for Node.js
https://www.fastify.dev
Other
32.02k stars 2.27k forks source link

fastify@5.0.0: 'FST_ERR_LOG_INVALID_LOGGER_CONFIG' when no log config is provided (works ok in fastify@4.28.1) #5702

Open seriousme opened 1 week ago

seriousme commented 1 week ago

Prerequisites

Fastify version

5.0.0

Plugin version

N/A

Node.js version

20.17.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

22.04

Description

Creating a fastify instance twice in a row (during testing) results in: 'FST_ERR_LOG_INVALID_LOGGER_CONFIG' while both times no logger config is provided. The bug does not trigger if only one instance is created. The error occurs in fastify@5.0.0 but works fine with fastify@4.28.1.

Link to code that reproduces the bug

https://gist.github.com/seriousme/a1456b1c0432d1029561025c6bdc4095

Expected Behavior

No error, just as I do not get an error in fastify@4.28.1

metcoder95 commented 6 days ago

👋 The issue you are facing is due to the fact that you are using the same noStrict options object for both fastify instances. This roots to the fact that, when instantiating a fastify app, fastify mutates the options object passed with the defaults of the options not provided.

As your example is reusing the same configuration object (which it is somehow polluted when trying to be used for second time) the validation fails while creating the second instance.

This might be countered as bug, so we can do a shallow copy of the object just to allow the object to be reused.

seriousme commented 6 days ago

Thanks,

shallow copy would be much appreciated as I was not expecting mutation of the options object.

Kind regards, Hans