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

Fix too eager dispose in js block tracing #6987

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ public GethLikeTxTrace Trace(Hash256 blockHash, int txIndex, GethTraceOptions op
_processor.Process(block, ProcessingOptions.Trace, blockTracer.WithCancellation(cancellationToken));
return blockTracer.BuildResult().SingleOrDefault();
}
finally
catch
Marchhill marked this conversation as resolved.
Show resolved Hide resolved
{
blockTracer.TryDispose();
throw;
}
}

Expand Down Expand Up @@ -177,9 +178,10 @@ public IEnumerable<string> TraceBlockToFile(Hash256 blockHash, GethTraceOptions
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken));
return tracer.BuildResult().SingleOrDefault();
}
finally
catch
{
tracer.TryDispose();
throw;
}
}

Expand Down Expand Up @@ -212,9 +214,10 @@ private IReadOnlyCollection<GethLikeTxTrace> TraceBlock(Block? block, GethTraceO
_processor.Process(block, ProcessingOptions.Trace, tracer.WithCancellation(cancellationToken));
return tracer.BuildResult();
}
finally
catch
{
tracer.TryDispose();
throw;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GethLikeBlockJavaScriptTracer : BlockTracerBase<GethLikeTxTrace, Ge
private readonly Context _ctx;
private readonly Db _db;
private int _index;
private ArrayPoolList<IDisposable>? _engines;
private List<IDisposable>? _engines;
private UInt256 _baseFee;

public GethLikeBlockJavaScriptTracer(IWorldState worldState, IReleaseSpec spec, GethTraceOptions options) : base(options.TxHash)
Expand All @@ -33,7 +33,7 @@ public GethLikeBlockJavaScriptTracer(IWorldState worldState, IReleaseSpec spec,

public override void StartNewBlockTrace(Block block)
{
_engines = new ArrayPoolList<IDisposable>(block.Transactions.Length + 1);
_engines = new List<IDisposable>(block.Transactions.Length + 1);
Marchhill marked this conversation as resolved.
Show resolved Hide resolved
_ctx.block = block.Number;
_ctx.BlockHash = block.Hash;
_baseFee = block.BaseFeePerGas;
Expand Down Expand Up @@ -75,11 +75,10 @@ public override void EndBlockTrace()
protected override GethLikeTxTrace OnEnd(GethLikeJavaScriptTxTracer txTracer) => txTracer.BuildResult();
public void Dispose()
{
ArrayPoolList<IDisposable>? list = Interlocked.Exchange(ref _engines, null);
List<IDisposable>? list = Interlocked.Exchange(ref _engines, null);
if (list is not null)
{
list.ForEach(e => e.Dispose());
list.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GethLikeJavaScriptTxTracer(
public override GethLikeTxTrace BuildResult()
{
GethLikeTxTrace result = base.BuildResult();
result.CustomTracerResult = new GethLikeCustomTrace() { Value = _tracer.result(_ctx, _db) };
result.CustomTracerResult = new GethLikeCustomTrace { Value = _tracer.result(_ctx, _db) };
_resultConstructed = true;
return result;
}
Expand Down