valkey-io / valkey-glide

An open source Valkey client library that supports Valkey and Redis open source 6.2, 7.0 and 7.2. Valkey GLIDE is designed for reliability, optimized performance, and high-availability, for Valkey and Redis OSS based applications. GLIDE is a multi language client library, written in Rust with programming language bindings, such as Java and Python
Apache License 2.0
262 stars 53 forks source link

Logger: thread panic in Vercel / NextJS if @valkey/valkey-glide attempts to log to file #2509

Closed ibolmo closed 3 weeks ago

ibolmo commented 3 weeks ago

Describe the bug

Deploying @valkey/valkey-glide to Vercel / nextjs will crash the serverless functions:

thread '<unnamed>' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-appender-0.2.3/src/rolling.rs:154:14:
initializing rolling file appender failed: InitError { context: "failed to create log directory", source: Os { code: 30, kind: ReadOnlyFilesystem, message: "Read-only file system" } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at library/core/src/panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace:
0:     0x7f89b83a1d1f - <unknown>
1:     0x7f89b810c62b - <unknown>
2:     0x7f89b83767ee - <unknown>
3:     0x7f89b83a65ce - <unknown>
4:     0x7f89b83a76ab - <unknown>
5:     0x7f89b83a6f52 - <unknown>
6:     0x7f89b83a6ee9 - <unknown>
7:     0x7f89b83a6ed4 - <unknown>
8:     0x7f89b80cbde4 - <unknown>
9:     0x7f89b80cbe4c - <unknown>
10:     0x7f89b80cbdf9 - <unknown>
11:     0x7f89b8217f99 - <unknown>
12:     0x56462976b63e - _ZN6v8impl12_GLOBAL__N_123FunctionCallbackWrapper6InvokeERKN2v820FunctionCallbackInfoINS2_5ValueEEE
13:     0x564629abb41f - _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
14:     0x564629abbd19 - _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEENS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EEPmi
15:     0x564629abc225 - _ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE
16:     0x56462a5ff1b6 - Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit
thread caused non-unwinding panic. aborting.

Tried multiple workarounds:

Logger.log = () => void 0;
Logger.setLoggerConfig("error", undefined);

But I still ran into the same problem. I believe the library is initializing the library on load of the module.

Expected Behavior

Make file appending lazy such that setLoggerConfig with an undefined file name disables file name based logging.

Current Behavior

The library attempts to create a logging directory automatically.

Reproduction Steps

  1. Create a nextjs app with a app route cache for testing purposes. Simple GET/POST to set/get a key value.
  2. Set next.config.js to config -> experimental -> serverComponentsExternalPackages to include "@valkey/valkey-glide"
  3. Deploy to vercel. Make sure you're using NodeJS 20.x.
  4. Attempt to set/get a key.
  5. See logs with panic errors.

Possible Solution

Avoid creating the directory until logs are configured. Perhaps always assume stdout and only if configured to use files should the library use file logging.

Additional Information/Context

No response

Client version used

1.1.0

Engine type and version

Redis 7.x

OS

Vercel

Language

TypeScript

Language Version

TypeScript ^5.0.3

Cluster information

No response

Logs

No response

Other information

No response

avifenesh commented 3 weeks ago

Hi :) Thanks for opening the issue! This issue was brought up and fixed, yet not released - 2387. It will be officially released in a month, and meanwhile a release candidate will be out very soon with the fix. I'm closing the issue, please follow up in the issue linked, I'll post there when the candidate is out and can be used.