Skip to content

Conversation

@maciejwalkowiak
Copy link
Contributor

📜 Description

Resolve servername from the localhost address.

💡 Motivation and Context

Fixes #1109.

Large piece of code - resolving and caching the server name has been copied from 1.7.x and updated to new standards.

💚 How did you test it?

Unit tests.

📝 Checklist

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

@codecov-io
Copy link

codecov-io commented Dec 30, 2020

Codecov Report

Merging #1146 (59c4e8d) into main (f6bca67) will increase coverage by 0.04%.
The diff coverage is 79.59%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1146      +/-   ##
============================================
+ Coverage     75.23%   75.28%   +0.04%     
- Complexity     1627     1639      +12     
============================================
  Files           167      168       +1     
  Lines          5637     5684      +47     
  Branches        555      557       +2     
============================================
+ Hits           4241     4279      +38     
- Misses         1144     1150       +6     
- Partials        252      255       +3     
Impacted Files Coverage Δ Complexity Δ
...ry/src/main/java/io/sentry/MainEventProcessor.java 75.71% <50.00%> (-2.42%) 24.00 <2.00> (+2.00) ⬇️
sentry/src/main/java/io/sentry/SentryOptions.java 84.98% <50.00%> (-0.53%) 113.00 <1.00> (+1.00) ⬇️
sentry/src/main/java/io/sentry/HostnameCache.java 89.18% <89.18%> (ø) 9.00 <9.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 f6bca67...59c4e8d. Read the comment docs.

}

private void handleCacheUpdateFailure() {
expirationTimestamp = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a class called CurrentDateProvider which returns a System.currentTimeMillis() so you could unit test if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

If it fails to resolve, it'll kick off again after 1 second.
We catch any error here and set it to 1 second again. So basically this can mean we keep spawning a new thread every second. I think in case of error we should just stop running this and just return null.

WHat makes this fail? Are those errors recoverable? is this a reverse DNS query on the local interface IP addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Failure is unlikely to happen, I can't think of the case when it would actually happen. Code has changed to use single daemon thread so that at least we don't spawn new threads all the time.

*
* @see HostnameCache
*/
private static final long HOSTNAME_CACHE_DURATION = TimeUnit.HOURS.toMillis(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

is it a common thing to change the server name? 5h seems too little, looks like also something we could have on the options, but not worth it at the moment

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 honestly don't know. This is how it was implemented in 1.x so I believe there was a reason for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, makes sense, not sure if it's worth copying blindly tbh, it's a lot of code and complexity for a simple workaround that would be restarting/redeploying the App, of course, it's suboptimal, but a redeploy would happen soon or later right.

thoughts @bruno-garcia ?

}

private void handleCacheUpdateFailure() {
expirationTimestamp = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(1);
Copy link
Member

Choose a reason for hiding this comment

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

If it fails to resolve, it'll kick off again after 1 second.
We catch any error here and set it to 1 second again. So basically this can mean we keep spawning a new thread every second. I think in case of error we should just stop running this and just return null.

WHat makes this fail? Are those errors recoverable? is this a reverse DNS query on the local interface IP addresses?

@maciejwalkowiak
Copy link
Contributor Author

@bruno-garcia I can't think of scenario where resolving server name would fail, as InetAddress#getHostFromNameService in case of failure returns just an ip address.

Btw, this is how it was implemented in 1.x.

@maciejwalkowiak
Copy link
Contributor Author

It's now disabled for android and turned on by default when just using Sentry dependency.

@bruno-garcia bruno-garcia merged commit d8efafe into main Jan 6, 2021
@bruno-garcia bruno-garcia deleted the gh-1109 branch January 6, 2021 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Servername no longer defaults to hostname

5 participants