Skip to content

Commit

Permalink
test(cactus-core): fix false negative test results
Browse files Browse the repository at this point in the history
The fix was to start statically importing the http helper library we use
in `packages/cactus-core/src/main/typescript/web-services/handle-rest-endpoint-exception.ts`
instead of how it was (dynamic imports at runtime).

1. There have been reports of dynamic imports causing segmentation
faults in the NodeJS process when Jest is involved.
2. It is looking like this bug was another instance of that manifesting
but slightly differently because this time around Jest decided to hide
the stack trace of it as well.
3. Because of `2)` we have no specific evidence of the theory. We can only
say that the change in this commit made the problem go away, but since
there never was any crash logs or stack traces on the CI environment,
this remains a conjecture.
4. Trying to reproduce the issue locally failed even when using the
exact same versions of NodeJS and npm (and all the dependencies of course).
5. Based on `4)` it is likely that the segmentation fault is due to a
race condition in the lower level (C/C++) code of NodeJS and/or Jest.

Fixes #2966

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Feb 7, 2024
1 parent 4184cf2 commit 636c3b9
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { Response } from "express";
import createHttpError from "http-errors";

import {
identifierByCodes,
INTERNAL_SERVER_ERROR,
} from "http-errors-enhanced-cjs";

import {
Logger,
createRuntimeErrorWithCause,
safeStringifyException,
} from "@hyperledger/cactus-common";
import type { Response } from "express";
import createHttpError from "http-errors";

/**
* An interface describing the object containing the contextual information needed by the
Expand Down Expand Up @@ -41,10 +47,6 @@ export async function handleRestEndpointException(
): Promise<void> {
const errorAsSanitizedJson = safeStringifyException(ctx.error);

const { identifierByCodes, INTERNAL_SERVER_ERROR } = await import(
"http-errors-enhanced-cjs"
);

if (createHttpError.isHttpError(ctx.error)) {
ctx.res.status(ctx.error.statusCode);

Expand Down

0 comments on commit 636c3b9

Please sign in to comment.