Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle client overrides signals #37

Open
tatref opened this issue Jun 9, 2021 · 5 comments
Open

Oracle client overrides signals #37

tatref opened this issue Jun 9, 2021 · 5 comments

Comments

@tatref
Copy link

tatref commented Jun 9, 2021

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?

@kubo
Copy link
Owner

kubo commented Jun 10, 2021

This is same issue with oracle/node-oracledb#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");

@tatref
Copy link
Author

tatref commented Jun 10, 2021

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!

@kubo
Copy link
Owner

kubo commented Jun 11, 2021

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.

@tatref
Copy link
Author

tatref commented Jun 11, 2021

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?

@kubo
Copy link
Owner

kubo commented Jun 14, 2021

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."

@tatref tatref changed the title Privileges causes issues with signals Oracle client overrides signals Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants