Skip to content

Commit

Permalink
[CBRD-25087] Restart cub_javasp via signal if JNI crashes the process (
Browse files Browse the repository at this point in the history
  • Loading branch information
hgryoo authored Jan 30, 2024
1 parent fcbc69f commit d12a208
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 29 deletions.
4 changes: 3 additions & 1 deletion msg/de_DE.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ $ LOADDB
1357 Konvertieren der SQL-Zeichenfolge in eine breite Zeichenfolge ist fehlgeschlagen.
1358 Die Anzahl der betroffenen Zeilen ist unbekannt.

1359 Letzter Fehler
1359 Java VM crashed: %1$s

1360 Letzter Fehler

$set 6 MSGCAT_SET_INTERNAL
1 Fehler in Fehler-Subsystem (Zeile %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/en_US.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Check the path of the key file (_keys) and make sure that it includes proper key
1357 Converting SQL string to wide string failed.
1358 Number of rows affected is unknown.

1359 Last Error
1359 Java VM crashed: %1$s

1360 Last Error

$set 6 MSGCAT_SET_INTERNAL
1 Error in error subsystem (line %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/en_US/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,9 @@ Check the path of the key file (_keys) and make sure that it includes proper key
1357 Converting SQL string to wide string failed.
1358 Number of rows affected is unknown.

1359 Last Error
1359 Java VM crashed: %1$s

1360 Last Error

$set 6 MSGCAT_SET_INTERNAL
1 Error in error subsystem (line %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/es_ES.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Verifique la ruta del archivo de claves (_keys) y asegúrese de que incluya la c
1357 Error al convertir una cadena SQL a una cadena ancha.
1358 Se desconoce el número de filas afectadas.

1359 Ultimo error
1359 Java VM crashed: %1$s

1360 Ultimo error

$set 6 MSGCAT_SET_INTERNAL
1 Error en subsistema de error (linea %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/fr_FR.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Vérifiez le chemin du fichier de clé (_keys) et assurez-vous qu'il inclut la c
1357 La conversion d'une chaîne SQL en chaîne large a échoué.
1358 Le nombre de lignes affectées est inconnu.

1359 Dernière erreur
1359 Java VM crashed: %1$s

1360 Dernière erreur

$set 6 MSGCAT_SET_INTERNAL
1 Erreur dans le sous-système d'erreur (ligne %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/it_IT.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Controllare il percorso del file della chiave (_keys) e assicurarsi che includa
1357 La conversione della stringa SQL in una stringa ampia non è riuscita.
1358 Il numero di righe interessate è sconosciuto.

1359 Ultimo errore
1359 Java VM crashed: %1$s

1360 Ultimo errore

$set 6 MSGCAT_SET_INTERNAL
1 Errore nel sottosistema di errore (linea %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/ja_JP.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ $ LOADDB
1357 SQL 文字列からワイド文字列への変換に失敗しました。
1358 影響を受ける行数は不明です。

1359 ラストエラー
1359 Java VM crashed: %1$s

1360 ラストエラー

$set 6 MSGCAT_SET_INTERNAL
1 エラーサブシステムにエラー発生(ライン %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/km_KH.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Check the path of the key file (_keys) and make sure that it includes proper key
1357 Converting SQL string to wide string failed.
1358 Number of rows affected is unknown.

1359 Last Error
1359 Java VM crashed: %1$s

1360 Last Error

$set 6 MSGCAT_SET_INTERNAL
1 Error in error subsystem (line %1$d):
Expand Down
6 changes: 4 additions & 2 deletions msg/ko_KR.euckr/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ See the License for the specific language governing permissions and
$ limitations under the License.
$
$
$


$
$ $Id$
Expand Down Expand Up @@ -1443,7 +1443,9 @@ $ LOADDB
1357 SQL ���ڿ��� ���̵� ���ڿ��� ��ȯ ����.
1358 ������ ���� �� ���� �� �� ����.

1359 ������ ����
1359 Java VM �� ��ְ� �߻���. : %1$s

1360 ������ ����

$set 6 MSGCAT_SET_INTERNAL
1 ���� ���� �ý��ۿ� ���� �߻�(���� %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/ko_KR.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ $ LOADDB
1357 SQL 문자열을 와이드 문자열로 변환 실패.
1358 영향을 받은 행 수를 알 수 없음.

1359 마지막 에러
1359 Java VM 에 장애가 발생함. : %1$s

1360 마지막 에러

$set 6 MSGCAT_SET_INTERNAL
1 에러 서브 시스템에 에러 발생(라인 %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/ro_RO.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Verificați calea fișierului cheie (_keys) și asigurați-vă că acesta includ
1357 Conversia șirului SQL în șir larg a eșuat.
1358 Numărul de rânduri afectate este necunoscut.

1359 Ultima eroare
1359 Java VM crashed: %1$s

1360 Ultima eroare

$set 6 MSGCAT_SET_INTERNAL
1 Eroare în subsistemul de erori (linia %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/tr_TR.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,9 @@ Anahtar dosyasının (_keys) yolunu kontrol edin ve uygun anahtarı içerdiğind
1357 SQL dizesini geniş dizeye dönüştürme işlemi başarısız oldu.
1358 Etkilenen satır sayısı bilinmiyor.

1359 Son Hata
1359 Java VM crashed: %1$s

1360 Son Hata

$set 6 MSGCAT_SET_INTERNAL
1 Alt Hata içinde hata (satır %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/vi_VN.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,9 @@ Check the path of the key file (_keys) and make sure that it includes proper key
1357 Converting SQL string to wide string failed.
1358 Number of rows affected is unknown.

1359 Last Error
1359 Java VM crashed: %1$s

1360 Last Error

$set 6 MSGCAT_SET_INTERNAL
1 Error in error subsystem (line %1$d):
Expand Down
4 changes: 3 additions & 1 deletion msg/zh_CN.utf8/cubrid.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,9 @@ $ LOADDB
1357 将 SQL 字符串转换为宽字符串失败。
1358 受影响的行数未知。

1359 最后一个错误.
1359 Java VM crashed: %1$s

1360 最后一个错误.

$set 6 MSGCAT_SET_INTERNAL
1 在错误子系统中错误 (line %1$d):
Expand Down
4 changes: 3 additions & 1 deletion src/base/error_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,9 @@
#define ER_CGW_SQL_CONV_ERROR -1357
#define ER_CGW_UNKNOWN_AFFECTED_ROWS -1358

#define ER_LAST_ERROR -1359
#define ER_SP_SERVER_CRASHED -1359

#define ER_LAST_ERROR -1360

/*
* CAUTION!
Expand Down
103 changes: 102 additions & 1 deletion src/executables/javasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

#include "config.h"

#if !defined(WINDOWS)
#include <dlfcn.h>
#include <execinfo.h>
#endif
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -65,6 +70,7 @@
#include <string>
#include <algorithm>
#include <array>
#include <atomic>

#define JAVASP_PING_LEN PATH_MAX

Expand Down Expand Up @@ -96,6 +102,17 @@ static int javasp_check_database (const std::string &db_name, std::string &db_pa

static int javasp_get_port_param ();

#if !defined(WINDOWS)
static void javasp_signal_handler (int sig);
#endif

static bool is_signal_handling = false;
static char executable_path[PATH_MAX];

static std::string command;
static std::string db_name;
static JAVASP_SERVER_INFO running_info = JAVASP_SERVER_INFO_INITIALIZER;

/*
* main() - javasp main function
*/
Expand All @@ -105,7 +122,6 @@ main (int argc, char *argv[])
{
int status = NO_ERROR;
FILE *redirect = NULL; /* for ping */
std::string command, db_name;

#if defined(WINDOWS)
FARPROC jsp_old_hook = NULL;
Expand All @@ -114,6 +130,14 @@ main (int argc, char *argv[])
{
return ER_GENERIC_ERROR;
}

os_set_signal_handler (SIGABRT, javasp_signal_handler);
os_set_signal_handler (SIGILL, javasp_signal_handler);
os_set_signal_handler (SIGFPE, javasp_signal_handler);
os_set_signal_handler (SIGBUS, javasp_signal_handler);
os_set_signal_handler (SIGSEGV, javasp_signal_handler);
os_set_signal_handler (SIGSYS, javasp_signal_handler);

#endif /* WINDOWS */
{
/*
Expand Down Expand Up @@ -226,6 +250,8 @@ main (int argc, char *argv[])
status = javasp_start_server (jsp_info, db_name, pathname);
if (status == NO_ERROR)
{
command = "running";
javasp_read_info (db_name.c_str(), running_info);
do
{
SLEEP_MILISEC (0, 100);
Expand Down Expand Up @@ -282,6 +308,81 @@ main (int argc, char *argv[])
return status;
}

#if !defined(WINDOWS)
static void javasp_signal_handler (int sig)
{
JAVASP_SERVER_INFO jsp_info = JAVASP_SERVER_INFO_INITIALIZER;

if (os_set_signal_handler (sig, SIG_DFL) == SIG_ERR)
{
return;
}

if (is_signal_handling == true)
{
return;
}

int status = javasp_get_server_info (db_name, jsp_info); // if failed,
if (status == NO_ERROR && jsp_info.pid != JAVASP_PID_DISABLED)
{
(void) envvar_bindir_file (executable_path, PATH_MAX, UTIL_JAVASP_NAME);
if (command.compare ("running") != 0 || db_name.empty ())
{
return;
}

if (running_info.pid == jsp_info.pid && running_info.port == jsp_info.port)
{
is_signal_handling = true;
}
else
{
return;
}

int pid = getpid ();
std::string err_msg;

void *addresses[64];
int nn_addresses = backtrace (addresses, sizeof (addresses) / sizeof (void *));
char **symbols = backtrace_symbols (addresses, nn_addresses);

err_msg += "pid (";
err_msg += std::to_string (pid);
err_msg += ")\n";

for (int i = 0; i < nn_addresses; i++)
{
err_msg += symbols[i];
if (i < nn_addresses - 1)
{
err_msg += "\n";
}
}
free (symbols);

er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_SERVER_CRASHED, 1, err_msg.c_str ());
pid = fork ();
if (pid == 0) // child
{
execl (executable_path, UTIL_JAVASP_NAME, "start", db_name.c_str (), NULL);
exit (0);
}
else
{
exit (1);
}
}
else
{
// resume signal hanlding
os_set_signal_handler (sig, javasp_signal_handler);
is_signal_handling = false;
}
}
#endif

static int
javasp_get_port_param ()
{
Expand Down
22 changes: 10 additions & 12 deletions src/jsp/jsp_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,13 @@ jsp_start_server (const char *db_name, const char *path, int port)
jobjectArray args;
JavaVMInitArgs vm_arguments;
JavaVMOption *options;
int vm_n_options = 3;
int vm_n_default_options = 2;
int vm_n_ext_options = 0;
char classpath[PATH_MAX + 32] = { 0 };
char logging_prop[PATH_MAX + 32] = { 0 };
char option_debug[70];
char debug_flag[] = "-Xdebug";
char debug_jdwp[] = "-agentlib:jdwp=transport=dt_socket,server=y,address=%d,suspend=n";
char disable_sig_handle[] = "-Xrs";
const char *envroot;
const char *uds_path;
char jsp_file_path[PATH_MAX];
Expand Down Expand Up @@ -552,42 +552,40 @@ jsp_start_server (const char *db_name, const char *path, int port)
debug_port = prm_get_integer_value (PRM_ID_JAVA_STORED_PROCEDURE_DEBUG);
if (debug_port != -1)
{
vm_n_options += 2; /* set debug flag and debugging port */
vm_n_default_options += 2; /* set debug flag and debugging port */
}

jvm_opt_sysprm = (char *) prm_get_string_value (PRM_ID_JAVA_STORED_PROCEDURE_JVM_OPTIONS);
// *INDENT-OFF*
std::vector <std::string> opts = jsp_tokenize_jvm_options (jvm_opt_sysprm);
// *INDENT-ON*
vm_n_options += (int) opts.size ();
options = new JavaVMOption[vm_n_options];
vm_n_ext_options += (int) opts.size ();
options = new JavaVMOption[vm_n_default_options + vm_n_ext_options];
if (options == NULL)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 0);
goto error;
}

int idx = 3;
int ext_idx = vm_n_default_options;
options[0].optionString = classpath;
options[1].optionString = logging_prop;
options[2].optionString = disable_sig_handle;
if (debug_port != -1)
{
idx += 2;
snprintf (option_debug, sizeof (option_debug) - 1, debug_jdwp, debug_port);
options[3].optionString = debug_flag;
options[4].optionString = option_debug;
options[2].optionString = debug_flag;
options[3].optionString = option_debug;
}

for (auto it = opts.begin (); it != opts.end (); ++it)
{
// *INDENT-OFF*
options[idx++].optionString = const_cast <char*> (it->c_str ());
options[ext_idx++].optionString = const_cast <char*> (it->c_str ());
// *INDENT-ON*
}

vm_arguments.version = JNI_VERSION_1_6;
vm_arguments.nOptions = vm_n_options;
vm_arguments.nOptions = vm_n_default_options + vm_n_ext_options;
vm_arguments.options = options;
vm_arguments.ignoreUnrecognized = JNI_TRUE;

Expand Down

0 comments on commit d12a208

Please sign in to comment.