questdb / questdb/java-questdb-client

InternalError thrown from MmapSegmentRecoveryFaultTest.testScanFaultOnMapPastEofIsHandledAnyFilesystem()

Open
#69 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
10
Forks
6
Avg merge
6h 40m
Merged PRs (30d)
2

Description

To reproduce

What failed: one test on the JDK 8 job — MmapSegmentRecoveryFaultTest.testHeaderFaultOnMapPastEofIsSkippableAnyFilesystem — with java.lang.InternalError: a fault occurred in
a recent unsafe memory access operation in compiled Java code (1 error out of 2792 → BUILD FAILURE).
This is QWP store-and-forward mmap-recovery code, from commit 5cc68a9 (fix(qwp): recover an SF slot whose segment tail is an unbacked mapped page (#64)).

Root cause (the interesting part): MmapSegment.openExisting reads the header magic via Unsafe.getInt on a page mapped beyond EOF,
wrapped in catch (Throwable t) → isMmapAccessFault(t) → convert to MmapSegmentException (line 328/345).
But the CI stack trace shows the InternalError at the test's line 292 with no openExisting frame — under the JDK 8 C2 JIT, openExisting gets inlined and
the "recent unsafe access" fault is thrown asynchronously at the inlined call site, bypassing the inlined catch (so isMmapAccessFault never even runs).
The author knew this territory is fragile — scanFrames has its own catch (InternalError) with a long comment about pre-21-JDK fault catchability, and the sibling
test explicitly tolerates the "C2: fault escaped to openExisting's outer catch" case. The difference: the branch runs a much larger suite (all the OIDC feature tests, already there before my review), which warms the JIT enough to C2-compile openExisting by the time this test runs; main's smaller suite leaves it interpreted/C1, where the catch holds.

Recommendation

This is a pre-existing flake in #64's QWP recovery code, surfaced by the branch's larger test suite — not something to fix in the OIDC review PR, and I won't blind-patch delicate JDK-8 Unsafe-fault code I can't reproduce locally (I'm on JDK 17/macOS). The fix belongs in #64's code and needs a JDK 8 environment to verify. Options for whoever owns it:

  1. Make the header-fault conversion C2-robust — keep the faulting Unsafe.getInt header read in a non-inlinable frame (a @DontInline/CompilerControl barrier, or a small helper scanFrames-style with its own tight catch (InternalError)) so the async fault can't escape an inlined catch.
  2. Route the recovery test through SegmentRing (the real recovery path) rather than calling MmapSegment.openExisting directly, matching how production actually skips a bad .sfa.

Log:

[INFO] Running io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest
14:09:53.723 [main] WARN io.questdb.client.cutlass.qwp.client.sf.cursor.MmapSegment -- SF segment /tmp/qdb-mmap-recover-168048958392/seg-unbacked-payload.sfa: torn tail of 1040400 bytes at offset 8176 (file size 1048576, frames recovered 1). Recovery will overwrite this region on next append; frames past the tear (if any) are discarded. Investigate disk health or unexpected writer crash.
14:09:53.724 [main] WARN io.questdb.client.cutlass.qwp.client.sf.cursor.MmapSegment -- SF segment /tmp/qdb-mmap-recover-168050228340/seg-mappasteof-scan.sfa: torn tail of 4096 bytes at offset 4096 (file size 8192, frames recovered 1). Recovery will overwrite this region on next append; frames past the tear (if any) are discarded. Investigate disk health or unexpected writer crash.
Error:  Tests run: 5, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.008 s <<< FAILURE! -- in io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest
Error:  io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest.testScanFaultOnMapPastEofIsHandledAnyFilesystem -- Time elapsed: 0.004 s <<< ERROR!
java.lang.InternalError: a fault occurred in a recent unsafe memory access operation in compiled Java code
	at io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest.lambda$testScanFaultOnMapPastEofIsHandledAnyFilesystem$3(MmapSegmentRecoveryFaultTest.java:257)
	at io.questdb.client.test.tools.TestUtils.assertMemoryLeak(TestUtils.java:129)
	at io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest.testScanFaultOnMapPastEofIsHandledAnyFilesystem(MmapSegmentRecoveryFaultTest.java:242)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)

Error:  io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest.testHeaderFaultOnMapPastEofIsSkippableAnyFilesystem -- Time elapsed: 0.001 s <<< ERROR!
java.lang.InternalError: a fault occurred in a recent unsafe memory access operation in compiled Java code
	at io.questdb.client.cutlass.qwp.client.sf.cursor.MmapSegment.openExisting(MmapSegment.java:332)
	at io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest.lambda$testHeaderFaultOnMapPastEofIsSkippableAnyFilesystem$4(MmapSegmentRecoveryFaultTest.java:292)
	at io.questdb.client.test.tools.TestUtils.assertMemoryLeak(TestUtils.java:129)
	at io.questdb.client.test.cutlass.qwp.client.sf.cursor.MmapSegmentRecoveryFaultTest.testHeaderFaultOnMapPastEofIsSkippableAnyFilesystem(MmapSegmentRecoveryFaultTest.java:283)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
QuestDB version:

latest

OS, in case of Docker specify Docker and the Host OS:

JDK 8 CI pipeline

File System, in case of Docker specify Host File System:

JDK 8 CI pipeline

Full Name:

glasstiger

Affiliation:

QuestDB

Have you followed Linux, MacOs kernel configuration steps to increase Maximum open files and Maximum virtual memory areas limit?
  • Yes, I have
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MmapSegment.openExisting in MmapSegment.java and the failing MmapSegmentRecoveryFaultTest methods testScanFaultOnMapPastEofIsHandledAnyFilesystem and testHeaderFaultOnMapPastEofIsSkippableAnyFilesystem. Run these tests in a JDK 8 environment, then verify that the map-past-EOF fault is handled reliably under the CI compilation conditions and the test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.