#TimeoutOverflowWarning (Cache Manager) Issue

7 messages · Page 1 of 1 (latest)

mint panther
#

I am having an issue that I'm struggling to track down. Here is the stack trace:

(node:28961) TimeoutOverflowWarning: 3153600001 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
    at new Timeout (node:internal/timers:173:17)
    at setTimeout (node:timers:164:19)
    at #setItemTTL (/Users/dwood/Sites/_microservices/docuware.microservice/node_modules/lru-cache/dist/commonjs/index.js:418:27)
    at LRUCache.set (/Users/dwood/Sites/_microservices/docuware.microservice/node_modules/lru-cache/dist/commonjs/index.js:913:33)
    at Object.set (/Users/dwood/Sites/_microservices/docuware.microservice/node_modules/cache-manager/dist/stores/memory.js:60:22)
    at Object.set (/Users/dwood/Sites/_microservices/docuware.microservice/node_modules/cache-manager/dist/caching.js:58:41)
    at DocuwareService.getCookie (/Users/dwood/Sites/_microservices/docuware.microservice/dist/docuware/docuware.service.js:78:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DocuwareService.getToken (/Users/dwood/Sites/_microservices/docuware.microservice/dist/docuware/docuware.service.js:37:26)
    at async DocumentsService.upload (/Users/dwood/Sites/_microservices/docuware.microservice/dist/docuware/documents/documents.service.js:44:23)
lunar hedge
#

Can you show DocuwareService? Specifically getCookie, getToken, and upload?

mint panther
#
import { HttpService } from '@nestjs/axios'
import { CACHE_MANAGER } from '@nestjs/cache-manager'
import { Inject, Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { AxiosRequestConfig, NtlmClient, NtlmCredentials } from 'axios-ntlm'
import { Cache } from 'cache-manager'
import { Agent } from 'https'
import { firstValueFrom } from 'rxjs'

@Injectable()
export class DocuwareService {
    ServerUrl: string
    Platform: string
    TokenUrl: string
    constructor(
        private readonly axios: HttpService,
        private readonly config: ConfigService,
        @Inject(CACHE_MANAGER) private cacheManager: Cache
    ) {
        this.ServerUrl = this.config.get<string>('DOCUWARE_SERVER_URL')
        this.Platform = this.config.get<string>('DOCUWARE_PLATFORM')
        this.TokenUrl = this.config.get<string>('ACCESS_TOKEN_URL')
    }```
#
async getToken(): Promise<string> {
        const token = await this.cacheManager.get<string>('TOKEN')
        if (!token) {
            let Cookie = await this.cacheManager.get<string>('NTLM_COOKIE')

            if (!Cookie) {
            }
            Cookie = await this.getCookie()

            const params = new URLSearchParams()
            params.append('grant_type', 'windows')
            params.append('scope', 'docuware.platform')
            params.append('client_id', 'docuware.platform.net.client')

            const {
                data: { access_token }
            } = await firstValueFrom(
                this.axios.post(`${this.ServerUrl}/${this.TokenUrl}`, params, {
                    headers: {
                        Cookie
                    },
                    httpsAgent: new Agent({
                        rejectUnauthorized: false
                    })
                })
            )

            await this.cacheManager.set('TOKEN', access_token, 60 * 60 * 1000)
            return access_token
        }
        return token
    }```
#
private async getCookie(): Promise<string> {
        const WindowsAuthUrl = this.config.get<string>('WINDOWS_AUTH_URL')
        const username = await this.config.get<string>('DOCUWARE_USERNAME')
        const password = await this.config.get<string>('DOCUWARE_PASSWORD')

        const credentials: NtlmCredentials = {
            username,
            password,
            domain: ''
        }

        const config: AxiosRequestConfig = {
            baseURL: this.ServerUrl,
            method: 'get',
            httpsAgent: new Agent({
                rejectUnauthorized: false,
                keepAlive: true
            })
        }

        const client = NtlmClient(credentials, config)

        const { headers } = await client.get('/' + WindowsAuthUrl)
        const cookie = headers['set-cookie'][0]
        await this.cacheManager.set('NTLM_COOKIE', cookie, 365 * 24 * 60 * 60 * 100)
        return cookie
    }```
lunar hedge
#

Okay, so cache-manager is using lru-cache under the hood, which is using setTimeout which relies on 32 bit integers. The max a 32 bit integer can be set to is 2147483647, which is less than your centi-seconds in a year (milliseconds would be *1000). So generally speaking, it looks like you can't cache that value for that amount of time

mint panther
#

Ah...ok