Skip to content
Open
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
16 changes: 14 additions & 2 deletions chronos/apps/http/httpbodyrw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ proc leakHttpBodyReader(): bool {.gcsafe.} =
var tracker = getHttpBodyReaderTracker()
tracker.opened != tracker.closed

proc resetHttpBodyWriter() {.gcsafe.} =
var tracker = getHttpBodyWriterTracker()
tracker.opened = 0
tracker.closed = 0

proc resetHttpBodyReader() {.gcsafe.} =
var tracker = getHttpBodyReaderTracker()
tracker.opened = 0
tracker.closed = 0

proc trackHttpBodyWriter(t: HttpBodyWriter) {.inline.} =
inc(getHttpBodyWriterTracker().opened)

Expand All @@ -77,15 +87,17 @@ proc untrackHttpBodyReader*(t: HttpBodyReader) {.inline.} =
proc setupHttpBodyWriterTracker(): HttpBodyTracker {.gcsafe.} =
var res = HttpBodyTracker(opened: 0, closed: 0,
dump: dumpHttpBodyWriterTracking,
isLeaked: leakHttpBodyWriter
isLeaked: leakHttpBodyWriter,
reset: resetHttpBodyWriter
)
addTracker(HttpBodyWriterTrackerName, res)
res

proc setupHttpBodyReaderTracker(): HttpBodyTracker {.gcsafe.} =
var res = HttpBodyTracker(opened: 0, closed: 0,
dump: dumpHttpBodyReaderTracking,
isLeaked: leakHttpBodyReader
isLeaked: leakHttpBodyReader,
reset: resetHttpBodyReader
)
addTracker(HttpBodyReaderTrackerName, res)
res
Expand Down
24 changes: 21 additions & 3 deletions chronos/apps/http/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ proc leakHttpClientResponse(): bool {.gcsafe.} =
var tracker = getHttpClientResponseTracker()
tracker.opened != tracker.closed

proc resetHttpClientConnection() {.gcsafe.} =
var tracker = getHttpClientConnectionTracker()
tracker.opened = 0
tracker.closed = 0

proc resetHttpClientRequest() {.gcsafe.} =
var tracker = getHttpClientRequestTracker()
tracker.opened = 0
tracker.closed = 0

proc resetHttpClientResponse() {.gcsafe.} =
var tracker = getHttpClientResponseTracker()
tracker.opened = 0
tracker.closed = 0

proc trackHttpClientConnection(t: HttpClientConnectionRef) {.inline.} =
inc(getHttpClientConnectionTracker().opened)

Expand All @@ -254,23 +269,26 @@ proc untrackHttpClientResponse*(t: HttpClientResponseRef) {.inline.} =
proc setupHttpClientConnectionTracker(): HttpClientTracker {.gcsafe.} =
var res = HttpClientTracker(opened: 0, closed: 0,
dump: dumpHttpClientConnectionTracking,
isLeaked: leakHttpClientConnection
isLeaked: leakHttpClientConnection,
reset: resetHttpClientConnection
)
addTracker(HttpClientConnectionTrackerName, res)
res

proc setupHttpClientRequestTracker(): HttpClientTracker {.gcsafe.} =
var res = HttpClientTracker(opened: 0, closed: 0,
dump: dumpHttpClientRequestTracking,
isLeaked: leakHttpClientRequest
isLeaked: leakHttpClientRequest,
reset: resetHttpClientRequest
)
addTracker(HttpClientRequestTrackerName, res)
res

proc setupHttpClientResponseTracker(): HttpClientTracker {.gcsafe.} =
var res = HttpClientTracker(opened: 0, closed: 0,
dump: dumpHttpClientResponseTracking,
isLeaked: leakHttpClientResponse
isLeaked: leakHttpClientResponse,
reset: resetHttpClientResponse
)
addTracker(HttpClientResponseTrackerName, res)
res
Expand Down
1 change: 1 addition & 0 deletions chronos/asyncloop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ type
id*: string
dump*: proc(): string {.gcsafe, raises: [Defect].}
isLeaked*: proc(): bool {.gcsafe, raises: [Defect].}
reset*: proc() {.gcsafe, raises: [Defect].}

PDispatcherBase = ref object of RootRef
timers*: HeapQueue[TimerCallback]
Expand Down
16 changes: 14 additions & 2 deletions chronos/streams/asyncstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ proc leakAsyncStreamWriter(): bool {.gcsafe.} =
var tracker = getAsyncStreamWriterTracker()
tracker.opened != tracker.closed

proc resetAsyncStreamReader() {.gcsafe.} =
var tracker = getAsyncStreamReaderTracker()
tracker.opened = 0
tracker.closed = 0

proc resetAsyncStreamWriter() {.gcsafe.} =
var tracker = getAsyncStreamWriterTracker()
tracker.opened = 0
tracker.closed = 0

proc trackAsyncStreamReader(t: AsyncStreamReader) {.inline.} =
var tracker = getAsyncStreamReaderTracker()
inc(tracker.opened)
Expand All @@ -403,7 +413,8 @@ proc setupAsyncStreamReaderTracker(): AsyncStreamTracker {.gcsafe.} =
opened: 0,
closed: 0,
dump: dumpAsyncStreamReaderTracking,
isLeaked: leakAsyncStreamReader
isLeaked: leakAsyncStreamReader,
reset: resetAsyncStreamReader
)
addTracker(AsyncStreamReaderTrackerName, res)
res
Expand All @@ -413,7 +424,8 @@ proc setupAsyncStreamWriterTracker(): AsyncStreamTracker {.gcsafe.} =
opened: 0,
closed: 0,
dump: dumpAsyncStreamWriterTracking,
isLeaked: leakAsyncStreamWriter
isLeaked: leakAsyncStreamWriter,
reset: resetAsyncStreamWriter
)
addTracker(AsyncStreamWriterTrackerName, res)
res
Expand Down
6 changes: 6 additions & 0 deletions chronos/transports/datagram.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ proc leakTransport(): bool {.gcsafe.} =
var tracker = getDgramTransportTracker()
result = (tracker.opened != tracker.closed)

proc resetTransport() {.gcsafe.} =
var tracker = getDgramTransportTracker()
tracker.opened = 0
tracker.closed = 0

proc trackDgram(t: DatagramTransport) {.inline.} =
var tracker = getDgramTransportTracker()
inc(tracker.opened)
Expand All @@ -131,6 +136,7 @@ proc setupDgramTransportTracker(): DgramTransportTracker {.gcsafe.} =
result.closed = 0
result.dump = dumpTransportTracking
result.isLeaked = leakTransport
result.reset = resetTransport
addTracker(DgramTransportTrackerName, result)

when defined(nimdoc):
Expand Down
12 changes: 12 additions & 0 deletions chronos/transports/stream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ proc leakServer(): bool {.gcsafe.} =
var tracker = getStreamServerTracker()
result = tracker.opened != tracker.closed

proc resetTransport() {.gcsafe.} =
var tracker = getStreamTransportTracker()
tracker.opened = 0
tracker.closed = 0

proc resetServer() {.gcsafe.} =
var tracker = getStreamServerTracker()
tracker.opened = 0
tracker.closed = 0

proc trackStream(t: StreamTransport) {.inline.} =
var tracker = getStreamTransportTracker()
inc(tracker.opened)
Expand All @@ -257,6 +267,7 @@ proc setupStreamTransportTracker(): StreamTransportTracker {.gcsafe.} =
result.closed = 0
result.dump = dumpTransportTracking
result.isLeaked = leakTransport
result.reset = resetTransport
addTracker(StreamTransportTrackerName, result)

proc setupStreamServerTracker(): StreamServerTracker {.gcsafe.} =
Expand All @@ -265,6 +276,7 @@ proc setupStreamServerTracker(): StreamServerTracker {.gcsafe.} =
result.closed = 0
result.dump = dumpServerTracking
result.isLeaked = leakServer
result.reset = resetServer
addTracker(StreamServerTrackerName, result)

proc completePendingWriteQueue(queue: var Deque[StreamVector],
Expand Down