microsoft / microsoft/FASTER

Error AccessViolationException ClientSession.Read on snapshot

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

Nobody has claimed this yet.

Dominant language
C#
Stars
6.6k
Forks
595
PR merge metrics
No merged PRs in 30d

Description

Example
_store.TryInitiateFullCheckpoint(out var snapshotId, CheckpointType.Snapshot);
_store.CompleteCheckpointAsync().AsTask().GetAwaiter().GetResult();
_store.Log.FlushAndEvict(true);
return new FasterDbSnapshot(this, _checkpointSettings, snapshotId);
//....
_snapshot = NullStorageDevice.Create(_checkpointSettings, out _logSettings);

_snapshot.Recover(_snapshotId);

_sessionPool = new(
    _logSettings.LogDevice.ThrottleLimit,
    () => _snapshot.For(new ByteArrayFunctions()).NewSession<ByteArrayFunctions>());
//...
public byte[]? TryGet(byte[] key)
{
    if (_sessionPool.TryGet(out var session) == false)
        session = _sessionPool.Get();

    var (status, output) = session.Read(key);  // <--- Throws Here, status is "FOUND", "output" is exception
    byte[]? value = null;

    if (status.Found)
        value = output;
    if (status.IsPending && session.CompletePendingWithOutputs(out var iter, true, true))
    {
        using (iter)
        {
            while (iter.Next())
            {
                if (iter.Current.Key.AsSpan().SequenceEqual(key))
                {
                    value = iter.Current.Output;
                    break;
                }
            }
        }
    }

    _sessionPool.Return(session);

    return value;
}
Exception
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
CallStack
 	FASTER.core.dll!FASTER.core.ByteArrayFasterEqualityComparer.Equals(ref byte[] k1, ref byte[] k2)	Unknown
 	FASTER.core.dll!FASTER.core.FasterKV<byte[], byte[]>.TraceBackForKeyMatch(ref byte[] key, ref FASTER.core.RecordSource<byte[], byte[]> recSrc, long minAddress)	Unknown
 	FASTER.core.dll!FASTER.core.FasterKV<byte[], byte[]>.InternalRead<byte[], byte[], FASTER.core.Empty, FASTER.core.ClientSession<byte[], byte[], byte[], byte[], FASTER.core.Empty, Neo.Build.Core.Storage.ByteArrayFunctions>.InternalFasterSession>(ref byte[] key, long keyHash, ref byte[] input, ref byte[] output, long startAddress, ref FASTER.core.Empty userContext, ref FASTER.core.FasterKV<byte[], byte[]>.PendingContext<byte[], byte[], FASTER.core.Empty> pendingContext, FASTER.core.ClientSession<byte[], byte[], byte[], byte[], FASTER.core.Empty, Neo.Build.Core.Storage.ByteArrayFunctions>.InternalFasterSession fasterSession, long lsn)	Unknown
 	FASTER.core.dll!FASTER.core.FasterKV<byte[], byte[]>.ContextRead<byte[], byte[], FASTER.core.Empty, FASTER.core.ClientSession<byte[], byte[], byte[], byte[], FASTER.core.Empty, Neo.Build.Core.Storage.ByteArrayFunctions>.InternalFasterSession>(ref byte[] key, ref byte[] input, ref byte[] output, FASTER.core.Empty context, FASTER.core.ClientSession<byte[], byte[], byte[], byte[], FASTER.core.Empty, Neo.Build.Core.Storage.ByteArrayFunctions>.InternalFasterSession fasterSession, long serialNo)	Unknown
 	FASTER.core.dll!FASTER.core.ClientSession<byte[], byte[], byte[], byte[], FASTER.core.Empty, Neo.Build.Core.Storage.ByteArrayFunctions>.Read(ref byte[] key, ref byte[] input, ref byte[] output, FASTER.core.Empty userContext, long serialNo)	Unknown
 	FASTER.core.dll!FASTER.core.ClientSession<byte[], byte[], byte[], byte[], FASTER.core.Empty, Neo.Build.Core.Storage.ByteArrayFunctions>.Read(byte[] key, FASTER.core.Empty userContext, long serialNo)	Unknown
>	Neo.Build.Core.dll!Neo.Build.Core.Storage.FasterDbSnapshot.TryGet(byte[] key) Line 114	C#

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 at Neo.Build.Core.Storage.FasterDbSnapshot.TryGet on line 114 and trace the snapshot creation and recovery sequence shown in the issue. Reproduce the call through ClientSession<byte[], byte[]>.Read, then inspect ByteArrayFunctions.Equals and the recovery state; done means TryGet no longer raises AccessViolationException for the recovered snapshot and returns the expected value.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.