rust-oracle
rust-oracle copied to clipboard
Oracle client overrides signals
Hi,
Environment:
- Oracle Linux 8.4
- Instance Client 18.5
- rust-oracle 0.5.1
When setting privileges, CTRL-C doesn't work anymore.
Reproducible example:
use oracle::{Connector, Privilege};
use std::thread;
use std::time::Duration;
fn main() {
let connector = Connector::new("sys", "sys", "localhost:1521/orcl.localdomain")
//.privilege(Privilege::Sysdba) <-- uncomment to trigger the issue
.to_owned();
let conn = connector.connect();
loop {
println!("try to CTRL-C! while I sleep...");
thread::sleep(Duration::from_millis(5_000));
}
}
I'm not exactly sure why, but the signals handlers are setup differently.
Below is the output of strace -e rt_sigaction,rt_sigprocmask ./target/release/main 2>&1 | grep INT
no privileges - does work
rt_sigprocmask(SIG_BLOCK, [INT], NULL, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x7f9ed5c54840, sa_mask=~[ILL TRAP ABRT BUS FPE SEGV USR2 TERM XCPU XFSZ SYS RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f9edc35bb30}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [INT], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [INT], NULL, 8) = 0
rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=~[ILL TRAP ABRT BUS FPE SEGV USR2 TERM XCPU XFSZ SYS RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f9edc35bb30}, {sa_handler=0x7f9ed5c54840, sa_mask=~[ILL TRAP ABRT BUS FPE KILL SEGV USR2 TERM STOP XCPU XFSZ SYS RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f9edc35bb30}, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [INT], NULL, 8) = 0
privileges - does not work
rt_sigprocmask(SIG_BLOCK, [INT], NULL, 8) = 0
rt_sigaction(SIGINT, {sa_handler=0x7f9ffb02d840, sa_mask=~[ILL TRAP ABRT BUS FPE SEGV USR2 TERM XCPU XFSZ SYS RTMIN RT_1], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7fa001734b30}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [INT], NULL, 8) = 0
Any idea?
This is same issue with https://github.com/oracle/node-oracledb/issues/128 and https://stackoverflow.com/questions/41811197/php-oci-connection-ignores-sigint-ctrl-c.
It doesn't depend on whether privilege is set or not. It depends on whether the connection is established successfully or not. I bet that connector.connect()
in your program fails because the sysdba privilege is necessary to connect with sys
user.
This issue will be fixed by replacing the SIGINT signal handler.
Add the followings to Cargo.toml
.
[dependencies]
ctrlc = "3.0"
libc = "0.2"
Then add the following code to main()
.
ctrlc::set_handler(|| unsafe {
libc::raise(libc::SIGTERM); // send SIGTERM instead of SIGINT to stop the process.
})
.expect("Error setting Ctrl-C handler");
You're right, of course the connection couldn't succeed with sys
:-)
So if I understand correctly, the issue lies in the instant client lib? or ODPI?
I'll try to override the handlers and report back here.
Thanks!
So if I understand correctly, the issue lies in the instant client lib? or ODPI?
In the client library. ODPI and rust-oracle don't change signal handlers.
Thanks for the kind support.
After some digging, I found the following note (an Oracle account is required):
11.2 Oracle Client overrides Application Signal Handler SIGINT (Doc ID 1401454.1)
The solution is to add a parameter to $instant_client/network/admin/sqlnet.ora
DISABLE_INTERRUPT=on
Is it worth a note in the Connect
methods for Connector
and Connection
?
Thanks for the information. I didn't know that.
I'll add a document about it. However I'll guide this link instead of the solution. That's because "My Oracle Support TERMS OF USE" includes "Except as specifically provided in your agreement with Oracle, the Materials may not be used to provide services for or to third parties and may not be shared with or accessed by third parties."