Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Crashes on AbortController aborts in Node #233

Open
prescience-data opened this issue May 9, 2023 · 0 comments
Open

Bug: Crashes on AbortController aborts in Node #233

prescience-data opened this issue May 9, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@prescience-data
Copy link

prescience-data commented May 9, 2023

Describe the bug
When the logger attempts to report an error thrown by a native Node AbortController, it appears to crash expecting a DOMException.

To Reproduce
Steps to reproduce the behavior:

const send = async <T>(request: T): Response => {
	const timeout = 10000 // 10s.
	const abort = new AbortController()
	
	// Abort request after timeout.
	const timer = setTimeout(() => {
	  abort.abort(`OpenAI request timed out.`)
	}, timeout)
	
	// Abortable request.
	return await fetch(
	  "api/with/long/timeout",
	  {
	    method: "POST",
	    body: JSON.stringify(request),
	    signal: abort.signal
	  }
	)
}

In the above case, TSLog will fatally error attempting to handle the uncaught abort signal.

However, if the abortable function is wrapped in a try/catch block with a native Node error, it appears to function correctly:

try {
	await send({ foo: true })
} catch(error) {
	logger.error(new Error(`Request error`))
}

Expected behavior
Without digging in to see if this is somewhat intentional or not, I would expect the logger to handle this type of error without fatal error (ie how other errors are handled successfully).

Error stack

node:internal/per_context/domexception:17
 const err = new Base();
             ^

TypeError: Value of "this" must be of DOMException
   at throwInvalidThisError (node:internal/per_context/domexception:17:15)
   at get name [as name] (node:internal/per_context/domexception:82:7)
   at formatError (node:internal/util/inspect:1362:20)
   at formatRaw (node:internal/util/inspect:986:14)
   at formatValue (node:internal/util/inspect:841:10)
   at inspect (node:internal/util/inspect:365:10)
   at formatWithOptionsInternal (node:internal/util/inspect:2273:40)
   at formatWithOptions (node:internal/util/inspect:2135:10)
   at transportFormatted (/home/<app>/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/runtime/nodejs/index.js:98:44)
   at Logger.log (/home/<app>/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/BaseLogger.js:121:34)
   at Logger.error (/home/<app>/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/index.js:29:22)
   at <anonymous> (/home/<app>/src/run.ts:71:10)
   at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
 code: 'ERR_INVALID_THIS'
}


Node.js Version
v18.16.0

OS incl. Version
Ubuntu 22.04

@prescience-data prescience-data added the bug Something isn't working label May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant