Skip to content

Commit

Permalink
close connection when binding space failed (#595)
Browse files Browse the repository at this point in the history
* close connection when binding space failed

* fix the close when auth failed
  • Loading branch information
Nicole00 committed May 24, 2024
1 parent 06945e3 commit 3d059c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public String executeJson(String stmt)
}

public String executeJsonWithParameter(String stmt,
Map<String, Object> parameterMap)
Map<String, Object> parameterMap)
throws ClientServerIncompatibleException, AuthFailedException,
IOErrorException, BindSpaceFailedException {
stmtCheck(stmt);
Expand Down Expand Up @@ -412,13 +412,27 @@ private NebulaSession createSessionObject(SessionState state)
sessionPoolConfig.getPassword());
} catch (AuthFailedException e) {
log.error(e.getMessage());
close();
if (e.getMessage().toLowerCase().contains("user not exist")
|| e.getMessage().toLowerCase().contains("invalid password")) {
// close the session pool
close();
} else {
// just close the connection
connection.close();
}
throw e;
}

NebulaSession nebulaSession = new NebulaSession(connection, authResult.getSessionId(),
authResult.getTimezoneOffset(), state);
ResultSet result = nebulaSession.execute(useSpace);
ResultSet result = null;
try {
result = nebulaSession.execute(useSpace);
} catch (IOErrorException e) {
log.error("binding space failed,", e);
nebulaSession.release();
throw new BindSpaceFailedException("binding space failed:" + e.getMessage());
}
if (!result.isSucceeded()) {
nebulaSession.release();
throw new BindSpaceFailedException(result.getErrorMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void open(HostAddress address, int timeout,
Charsets.UTF_8));
}
} catch (TException e) {
close();
throw new IOErrorException(IOErrorException.E_UNKNOWN, e.getMessage());
}
}
Expand Down

0 comments on commit 3d059c2

Please sign in to comment.