Skip to content

Commit

Permalink
Fix too eager dispose in js block tracing (#6987)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaszRozmej authored May 7, 2024
1 parent f679833 commit 7b161e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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
{
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);
_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

0 comments on commit 7b161e6

Please sign in to comment.