@@ -125,6 +125,16 @@ public static MatchByColumnName fromString(String value) {
125125 }
126126 }
127127
128+ // error codes which need reauthenticate
129+ // ref:
130+ // https://github.com/snowflakedb/snowflake-jdbc/blob/v3.13.26/src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java#L42
131+ private static final int ID_TOKEN_EXPIRED_GS_CODE = 390110 ;
132+ private static final int SESSION_NOT_EXIST_GS_CODE = 390111 ;
133+ private static final int MASTER_TOKEN_NOTFOUND = 390113 ;
134+ private static final int MASTER_EXPIRED_GS_CODE = 390114 ;
135+ private static final int MASTER_TOKEN_INVALID_GS_CODE = 390115 ;
136+ private static final int ID_TOKEN_INVALID_LOGIN_REQUEST_GS_CODE = 390195 ;
137+
128138 @ Override
129139 protected Class <? extends PluginTask > getTaskClass () {
130140 return SnowflakePluginTask .class ;
@@ -227,17 +237,25 @@ private void runDropStage(
227237 try {
228238 snowflakeCon .runDropStage (stageIdentifier );
229239 } catch (SnowflakeSQLException ex ) {
230- logger .info ("SnowflakeSQLException was caught: {}" , ex .getMessage ());
231-
232- if (ex .getMessage ().startsWith ("Authentication token has expired." )
233- || ex .getMessage ().startsWith ("Session no longer exists." )) {
234-
235- // INFO: If runCreateStage consumed a lot of time, authentication might be expired.
236- // In this case, retry to drop stage.
237- snowflakeCon = (SnowflakeOutputConnection ) getConnector (task , true ).connect (true );
238- snowflakeCon .runDropStage (stageIdentifier );
239- } else {
240- throw ex ;
240+ // INFO: Don't handle only SnowflakeReauthenticationRequest here
241+ // because SnowflakeSQLException with following error codes may be thrown in some cases.
242+
243+ logger .info ("SnowflakeSQLException was caught: ({}) {}" , ex .getErrorCode (), ex .getMessage ());
244+
245+ switch (ex .getErrorCode ()) {
246+ case ID_TOKEN_EXPIRED_GS_CODE :
247+ case SESSION_NOT_EXIST_GS_CODE :
248+ case MASTER_TOKEN_NOTFOUND :
249+ case MASTER_EXPIRED_GS_CODE :
250+ case MASTER_TOKEN_INVALID_GS_CODE :
251+ case ID_TOKEN_INVALID_LOGIN_REQUEST_GS_CODE :
252+ // INFO: If runCreateStage consumed a lot of time, authentication might be expired.
253+ // In this case, retry to drop stage.
254+ snowflakeCon = (SnowflakeOutputConnection ) getConnector (task , true ).connect (true );
255+ snowflakeCon .runDropStage (stageIdentifier );
256+ break ;
257+ default :
258+ throw ex ;
241259 }
242260 }
243261 }
0 commit comments