Skip to content

zLib memory retain due to references to Request Object #432

@thaoula

Description

@thaoula

Hi Team,

I am currently tracking a memory leak where zLib references are being retained and never released. We see this via memory snapshot taken by chrome. Deep inspection of these zlib references show they are request / response releated.

We are injecting CLS_REQ to get access to the Request object and we are not saving the request anywhere. The more we do this the more zLib increases.

zLib is involved here because we use the compression middleware for express.

I recently updated the code to do the following -

ClsModule.forRoot({
            global: true,
            middleware: {
                saveReq: false,
                mount: true,
                setup(cls, req, res) {
                    cls.set(CLS_REQ, {
                        user: req.user,
                        role: req.role,
                        headers: {
                            tenant: req.headers?.tenant,
                            parentid: req.headers?.parentid,
                            authorization: req.headers?.authorization,
                            host: req.headers?.host,
                            nonce: req.headers?.nonce,
                            'x-correlationid': req.headers?.['x-correlationid'],
                            'x-forwarded-for': req.headers?.['x-forwarded-for'],
                            'x-real-ip': req.headers?.['x-real-ip'],
                            'cf-connecting-ip': req.headers?.['cf-connecting-ip'],
                        },
                        ip: req.ip ?? req.socket?.remoteAddress ?? req.connection?.remoteAddress,
                        connectOptions: req.connectOptions,
                    });
                },
            },
        }),

Is this expected behaviour of saveReq: true?

Kind Regards,
Tarek

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions