sijms / go-ora

Pure go oracle client
MIT License
786 stars 174 forks source link

Long running stored procedure - socket is not connected error #437

Closed dekke046 closed 1 year ago

dekke046 commented 1 year ago

Hi,

I am having some issues with long running stored procedures (10+ minutes) causing read tcp 192.168.0.156:56028->192.168.0.156:1521: read: socket is not connected error.

To simulatie I am running Oracle in docker and created a very simple procedure:

create or replace PROCEDURE WaitAndFinish AS
BEGIN
  -- Procedure started
  DBMS_OUTPUT.PUT_LINE('Procedure started');
  -- Wait for 5 minutes (300 seconds)
  DBMS_LOCK.SLEEP(300);
  -- Procedure running 5 minutes
  DBMS_OUTPUT.PUT_LINE('Procedure running 5 minutes');
  -- Wait for 5 minutes (300 seconds)
  DBMS_LOCK.SLEEP(300);
  -- Procedure running another 5 minutes
  DBMS_OUTPUT.PUT_LINE('Procedure running another 5 minutes');
  -- Procedure finished after waiting for 10 minutes
  DBMS_OUTPUT.PUT_LINE('Procedure has finished after waiting for 10 minutes.');
END WaitAndFinish;

Then using:

    urlOptions := map[string]string{
        "TIMEOUT": "0",
    }

And simply call the procedure:

    // Call the stored procedure
    fmt.Println("Started stored procedure")
    t := time.Now()
    _, err = conn.Exec(`BEGIN waitandfinish(); END;`)
    if err != nil {
        fmt.Println("Failed running stored procedure:", err)
        fmt.Println("Stored procedure took:", time.Now().Sub(t))
        return
    }
    fmt.Println("Stored procedure took:", time.Now().Sub(t))

Gives the following error:

Started Loader
Connection string:  (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.156)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=XEPDB1)))
Started stored procedure
Failed running stored procedure: read tcp 192.168.0.156:58048->192.168.0.156:1521: read: socket is not connected
Stored procedure took: 10m0.187546811s
sijms commented 1 year ago

the error means oracle server is close the socket while your procedure is waiting would you please refer to this oracle docs

server sqlnet.ora parameters required

SQLNET.RECV_TIMEOUT
SQLNET.INBOUND_CONNECT_TIMEOUT