-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: Rewrite transport and queue to prevent memory leaks #1795
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
277c9a7
fix: Limit concurrent FS calls to prevent memory fragmentation
kamilogorek 8d14c6e
fix: Move limiter to node, Add frameContextLines option
HazAT 95ee999
Update .gitignore
HazAT 547945b
feat: Pass string into transport, Use request buffer directly in tran…
HazAT d60be01
feat: Use buffer in transport
HazAT 53e6341
feat: Add all changes for transport and buffers
HazAT 8ba0564
fix: Linter
HazAT 27e31bc
fix: Wording
HazAT a0e3339
fix: Don't break the API
HazAT 2b5d756
feat: Add simple lru cache for readFiles
HazAT 04fc2e8
meta: Code Review
HazAT f3c3882
meta: Linter errros
HazAT a353ef1
fix: Changelog + docs
HazAT 0b23311
fix: Browser integration tests
HazAT 68e5592
fix: Also cache if the file wasn't readable
HazAT 38053e4
fix: Linter
HazAT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import { SentryEvent, SentryResponse, Status } from '@sentry/types'; | ||
| import { SentryResponse, Status } from '@sentry/types'; | ||
| import { getGlobalObject } from '@sentry/utils/misc'; | ||
| import { serialize } from '@sentry/utils/object'; | ||
| import { BaseTransport } from './base'; | ||
|
|
||
| const global = getGlobalObject() as Window; | ||
|
|
@@ -10,13 +9,13 @@ export class BeaconTransport extends BaseTransport { | |
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public async captureEvent(event: SentryEvent): Promise<SentryResponse> { | ||
| const data = serialize(event); | ||
| public async sendEvent(body: string): Promise<SentryResponse> { | ||
| const result = global.navigator.sendBeacon(this.url, body); | ||
|
|
||
| const result = global.navigator.sendBeacon(this.url, data); | ||
|
|
||
| return { | ||
| status: result ? Status.Success : Status.Failed, | ||
| }; | ||
| return this.buffer.add( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure that we want to store it in the buffer here instead of doing it somewhere else? This way we are forcing users to write this code in all custom transports, otherwise it will skip the buffering completely. On the other hand, it gives them control over buffering... 🤔 |
||
| Promise.resolve({ | ||
| status: result ? Status.Success : Status.Failed, | ||
| }), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,33 @@ | ||
| import { SentryEvent, SentryResponse, Status } from '@sentry/types'; | ||
| import { serialize } from '@sentry/utils/object'; | ||
| import { SentryResponse, Status } from '@sentry/types'; | ||
| import { BaseTransport } from './base'; | ||
|
|
||
| /** `XHR` based transport */ | ||
| export class XHRTransport extends BaseTransport { | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public async captureEvent(event: SentryEvent): Promise<SentryResponse> { | ||
| return new Promise<SentryResponse>((resolve, reject) => { | ||
| const request = new XMLHttpRequest(); | ||
| public async sendEvent(body: string): Promise<SentryResponse> { | ||
| return this.buffer.add( | ||
| new Promise<SentryResponse>((resolve, reject) => { | ||
| const request = new XMLHttpRequest(); | ||
|
|
||
| request.onreadystatechange = () => { | ||
| if (request.readyState !== 4) { | ||
| return; | ||
| } | ||
| request.onreadystatechange = () => { | ||
| if (request.readyState !== 4) { | ||
| return; | ||
| } | ||
|
|
||
| if (request.status === 200) { | ||
| resolve({ | ||
| status: Status.fromHttpCode(request.status), | ||
| }); | ||
| } | ||
| if (request.status === 200) { | ||
| resolve({ | ||
| status: Status.fromHttpCode(request.status), | ||
| }); | ||
| } | ||
|
|
||
| reject(request); | ||
| }; | ||
| reject(request); | ||
| }; | ||
|
|
||
| request.open('POST', this.url); | ||
| request.send(serialize(event)); | ||
| }); | ||
| request.open('POST', this.url); | ||
| request.send(body); | ||
| }), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { SentryResponse, Status } from '../../src'; | ||
| import { BaseTransport } from '../../src/transports'; | ||
|
|
||
| export class SimpleTransport extends BaseTransport { | ||
| public async sendEvent(_: string): Promise<SentryResponse> { | ||
| return this.buffer.add( | ||
| Promise.resolve({ | ||
| status: Status.fromHttpCode(200), | ||
| }), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.