Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

ref: retrying thread pool executor is a single thread executor instead of scheduled thread executor #422

Merged
merged 5 commits into from
May 20, 2020
Merged

ref: retrying thread pool executor is a single thread executor instead of scheduled thread executor #422

merged 5 commits into from
May 20, 2020

Conversation

marandaneto
Copy link
Contributor

@marandaneto marandaneto commented May 19, 2020

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

ref: retrying thread pool executor is a single thread pool executor instead of a scheduled thread pool executor.

💡 Motivation and Context

it executes tasks one after the other and we don't have scheduled tasks at all.

💚 How did you test it?

running it, tests passed.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing

🔮 Next steps

@codecov-commenter
Copy link

codecov-commenter commented May 19, 2020

Codecov Report

Merging #422 into master will decrease coverage by 0.14%.
The diff coverage is 81.48%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #422      +/-   ##
============================================
- Coverage     60.19%   60.04%   -0.15%     
- Complexity      809      813       +4     
============================================
  Files            92       93       +1     
  Lines          3748     3742       -6     
  Branches        360      363       +3     
============================================
- Hits           2256     2247       -9     
- Misses         1338     1339       +1     
- Partials        154      156       +2     
Impacted Files Coverage Δ Complexity Δ
...c/main/java/io/sentry/core/cache/SessionCache.java 53.63% <ø> (ø) 23.00 <0.00> (ø)
.../src/main/java/io/sentry/core/SendCachedEvent.java 55.76% <66.66%> (+0.86%) 8.00 <0.00> (ø)
...re/src/main/java/io/sentry/core/util/LogUtils.java 70.00% <70.00%> (ø) 4.00 <4.00> (?)
...e/src/main/java/io/sentry/core/EnvelopeSender.java 66.31% <75.00%> (-0.70%) 16.00 <0.00> (ø)
...re/src/main/java/io/sentry/core/SentryOptions.java 80.53% <100.00%> (ø) 73.00 <0.00> (ø)
...java/io/sentry/core/transport/AsyncConnection.java 68.50% <100.00%> (-2.42%) 19.00 <0.00> (ø)
...entry/core/transport/QueuedThreadPoolExecutor.java 78.94% <100.00%> (ø) 7.00 <1.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0363118...6a438ad. Read the comment docs.

@@ -96,6 +96,9 @@ public void store(final @NotNull SentryEnvelope envelope, final @Nullable Object
}

if (hint instanceof SessionStart) {

// TODO: should we move this to AppLifecycleIntegration? and do on SDK init? but it's too much
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not do it or we find a different way to improve things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw on sentry-cocoa it's done on the thread calling init (expected to be the UI thread).
Agree it'd be best to avoid work on the UI thread but we need to make sure we don't race through the current session file which startSession would touch upon being called

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I do that before even calling the Lifeycicle callback, no racing.
But sentry-android does more things, like the crash marker from sentry-native with a timestamp, so a hard crash can lead to a few IOs more on the main-thread and at this point, I'd say that we are doing quite a bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, your call

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My points are mainly regarding other stuff that changed here but not really with the Single thread executor.

Also, it's worth noting now reading EnvelopeSender it does look like it needs refactoring.
Since we're unwrapping the envelope there and special casing things,maybe it's time to move that logic to the transport. In these Senders we just call captureEnvelope and in there we either call the envelope endpoint, or we unwrap them (code from current EnvelopeSender) to call the /store endpoint)

Main point to discuss is the Retryable hint bit. We need to be really conservative here because it can lead to different problems.

@@ -144,13 +146,18 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @Null
SentryLevel.WARNING,
"Timed out waiting for event submission: %s",
event.getEventId());

if (hint instanceof Retryable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H: Not sure about this. It could mean we're capturing events twice if we mark the event as retry=true and it actually finishes being sent. Why is this change introduced? We don't seem to have an issue missing events, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a timed out and not a known exception that returns immediately which is 99.9% of the cases (no connection or something), so it really didn't have time enough due to different things, eg, long queue, very slow connection and low-end device, taking more time to serialize/deserialize, etc, I did reproduce this using emulator and very bad configurations purposely

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It times out waiting for the synchronization mechanism to be called as opposed to an HTTP request timeout. It's very possible that we'll give up waiting here before the HTTP request times out (unless we guarantee that the HTTP request times out before this waitFlush method here.

It's also an issue where have some bug in the SDK and now we're keeping things forever because this method is never called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not talking about only http request timeout, it's altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed those Retryable checks from this PR and can come up with a new PR, merging this one without them

@@ -96,6 +96,9 @@ public void store(final @NotNull SentryEnvelope envelope, final @Nullable Object
}

if (hint instanceof SessionStart) {

// TODO: should we move this to AppLifecycleIntegration? and do on SDK init? but it's too much
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw on sentry-cocoa it's done on the thread calling init (expected to be the UI thread).
Agree it'd be best to avoid work on the UI thread but we need to make sure we don't race through the current session file which startSession would touch upon being called

@marandaneto
Copy link
Contributor Author

Also, it's worth noting now reading EnvelopeSender it does look like it needs refactoring.
Since we're unwrapping the envelope there and special casing things,maybe it's time to move that logic to the transport. In these Senders we just call captureEnvelope and in there we either call the envelope endpoint, or we unwrap them (code from current EnvelopeSender) to call the /store endpoint)

yeah, I believe that when we get to the point of getting rid of /store, this refactoring will come naturally, what do you think?

Main point to discuss is the Retryable hint bit. We need to be really conservative here because it can lead to different problems.

replied on the comment.

@marandaneto marandaneto merged commit 0b13b1d into getsentry:master May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants