shell: taos shell websocket reconnect error

This commit is contained in:
afwerar 2022-09-21 11:43:36 +08:00
parent 4ebdab3540
commit d3a21816cc
2 changed files with 23 additions and 18 deletions

View File

@ -143,7 +143,7 @@ void shellCheckConnectMode() {
shell.args.port = 6041; shell.args.port = 6041;
} }
shell.args.dsn = taosMemoryCalloc(1, 1024); shell.args.dsn = taosMemoryCalloc(1, 1024);
snprintf(shell.args.dsn, 1024, "ws://%s:%d/rest/ws", snprintf(shell.args.dsn, 1024, "ws://%s:%d",
shell.args.host, shell.args.port); shell.args.host, shell.args.port);
} }
shell.args.cloud = false; shell.args.cloud = false;

View File

@ -206,26 +206,31 @@ void shellRunSingleCommandWebsocketImp(char *command) {
printMode = true; // When output to a file, the switch does not work. printMode = true; // When output to a file, the switch does not work.
} }
if (!shell.ws_conn && shell_conn_ws_server(0)) {
return;
}
shell.stop_query = false; shell.stop_query = false;
st = taosGetTimestampUs(); WS_RES* res;
WS_RES* res = ws_query_timeout(shell.ws_conn, command, shell.args.timeout); for (int reconnectNum = 0; reconnectNum < 2; reconnectNum++) {
int code = ws_errno(res); if (!shell.ws_conn && shell_conn_ws_server(0)) {
if (code != 0) { return;
et = taosGetTimestampUs();
fprintf(stderr, "\nDB: error: %s (%.6fs)\n", ws_errstr(res), (et - st)/1E6);
if (code == TSDB_CODE_WS_SEND_TIMEOUT || code == TSDB_CODE_WS_RECV_TIMEOUT) {
fprintf(stderr, "Hint: use -t to increase the timeout in seconds\n");
} else if (code == TSDB_CODE_WS_INTERNAL_ERRO || code == TSDB_CODE_WS_CLOSED) {
fprintf(stderr, "TDengine server is down, will try to reconnect\n");
shell.ws_conn = NULL;
} }
ws_free_result(res); st = taosGetTimestampUs();
return;
res = ws_query_timeout(shell.ws_conn, command, shell.args.timeout);
int code = ws_errno(res);
if (code != 0 && !shell.stop_query) {
et = taosGetTimestampUs();
fprintf(stderr, "\nDB: error: %s (%.6fs)\n", ws_errstr(res), (et - st)/1E6);
if (code == TSDB_CODE_WS_SEND_TIMEOUT || code == TSDB_CODE_WS_RECV_TIMEOUT) {
fprintf(stderr, "Hint: use -t to increase the timeout in seconds\n");
} else if (code == TSDB_CODE_WS_INTERNAL_ERRO || code == TSDB_CODE_WS_CLOSED) {
fprintf(stderr, "TDengine server is down, will try to reconnect\n");
shell.ws_conn = NULL;
}
ws_free_result(res);
if (reconnectNum == 0) continue;
return;
}
break;
} }
double execute_time = ws_take_timing(res)/1E6; double execute_time = ws_take_timing(res)/1E6;