Skip to content
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

fix: actually use milliseconds instead of microseconds for timeouts #1653

Merged
merged 2 commits into from Jan 24, 2020

Conversation

davecramer
Copy link
Member

@davecramer davecramer commented Dec 17, 2019

No description provided.

@codecov-io
Copy link

@codecov-io codecov-io commented Dec 17, 2019

Codecov Report

Merging #1653 into master will increase coverage by 0.95%.
The diff coverage is 75%.

@@             Coverage Diff             @@
##             master   #1653      +/-   ##
===========================================
+ Coverage     67.85%   68.8%   +0.95%     
- Complexity     4042    4086      +44     
===========================================
  Files           181     181              
  Lines         16945   16957      +12     
  Branches       2774    2789      +15     
===========================================
+ Hits          11498   11668     +170     
+ Misses         4175    4012     -163     
- Partials       1272    1277       +5

Copy link
Member

@jorsol jorsol left a comment

What about using TimeUnit.NANOSECONDS.toMillis?
I think it's more clear and less error-prone.

@@ -397,7 +397,7 @@ public void run() {
* @throws SQLException if a connection error occurs or the timeout is reached
*/
public Connection getResult(long timeout) throws SQLException {
long expiry = System.nanoTime() / 1000 + timeout;
long expiry = System.nanoTime() / (long)1E6 + timeout;
Copy link
Member

@jorsol jorsol Dec 30, 2019

Choose a reason for hiding this comment

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

long expiry = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) + timeout;

@@ -416,7 +416,7 @@ public Connection getResult(long timeout) throws SQLException {
}
}

long delay = expiry - System.nanoTime() / 1000;
long delay = expiry - System.nanoTime() / (long)1E6;
Copy link
Member

@jorsol jorsol Dec 30, 2019

Choose a reason for hiding this comment

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

long delay = expiry - TimeUnit.NANOSECONDS.toMillis(System.nanoTime());

@@ -720,7 +720,7 @@ public synchronized void processNotifies(int timeoutMillis) throws SQLException
long startTime = 0;
int oldTimeout = 0;
if (useTimeout) {
startTime = System.nanoTime() / 1000;
startTime = System.nanoTime() / (long)1E6;
Copy link
Member

@jorsol jorsol Dec 30, 2019

Choose a reason for hiding this comment

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

startTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());

@@ -750,7 +750,7 @@ public synchronized void processNotifies(int timeoutMillis) throws SQLException
SQLWarning warning = receiveNoticeResponse();
addWarning(warning);
if (useTimeout) {
long newTimeMillis = System.nanoTime() / 1000;
long newTimeMillis = System.nanoTime() / (long)1E6;
Copy link
Member

@jorsol jorsol Dec 30, 2019

Choose a reason for hiding this comment

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

long newTimeMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());

@davecramer
Copy link
Member Author

@davecramer davecramer commented Dec 30, 2019

Thanks I'll change that

@davecramer davecramer merged commit 3dd5dff into pgjdbc:master Jan 24, 2020
1 of 2 checks passed
@davecramer davecramer deleted the fixnanos branch Jan 24, 2020
paplorinc added a commit to paplorinc/pgjdbc that referenced this issue Feb 10, 2020
* origin/master: (427 commits)
  refactor: make PSQLState enum consts for integrity constraint violations (pgjdbc#1699)
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release REL42.2.10
  pass gpg key through arguments
  add passphrase to release mvn task
  chore: update signing key
  Metadata queries improvment (pgjdbc#1694)
  WIP release notes for 42.2.10 (pgjdbc#1688)
  chore(deps): bump checkstyle from 8.28 to 8.29 in /pgjdbc (pgjdbc#1691)
  Cleanup PGProperty, sort values, and add some missing to docs (pgjdbc#1686)
  fix: Fixes issue pgjdbc#1592 where one thread is reading the copy and another thread closes the connection (pgjdbc#1594)
  Fixing LocalTime rounding (losing precision) (pgjdbc#1570)
  sync error message value with tested value (pgjdbc#1664)
  add DatabaseMetaDataCacheTest to test suite to run it (pgjdbc#1685)
  Fix Network Performance of PgDatabaseMetaData.getTypeInfo() method (pgjdbc#1668)
  fix: Issue pgjdbc#1680 updating a boolean field requires special handling to set it to t or f instead of true or false (pgjdbc#1682)
  fix testSetNetworkTimeoutEnforcement test failure (pgjdbc#1681)
  minor: fix checkstyle violation of unused import (pgjdbc#1683)
  fix: pgjdbc#1677 NumberFormatException when fetching PGInterval with small value (pgjdbc#1678)
  fix: actually use milliseconds instead of microseconds for timeouts (pgjdbc#1653)
  ...
davecramer added a commit to davecramer/pgjdbc that referenced this issue Jul 5, 2021
…gjdbc#1653)

* fix: actually use milliseconds instead of microseconds for timeouts

* Use TimeUnit to convert to millis
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.

None yet

3 participants