http: panic serving 127.0.0.1:43974: runtime error: index out of range [0] with length 0
I trying to execute a procedure, its working but failed when lot of users comes in the system. this is the error
Jul 30 12:23:50 : 2024/07/30 12:23:50 http: panic serving 127.0.0.1:43974: runtime error: index out of range [0] with length 0 Jul 30 12:23:50 : goroutine 26 [running]: Jul 30 12:23:50 : net/http.(*conn).serve.func1() Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/net/http/server.go:1868 +0xb9 Jul 30 12:23:50 : panic({0xa57c20?, 0xc000204840?}) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/runtime/panic.go:920 +0x270 Jul 30 12:23:50 : github.com/sijms/go-ora/v2.(*DataSet).setBitVector(0xc000232000?, {0xc000102900?, 0xc000081b70?, 0x434c9b?}) Jul 30 12:23:50 : C:/Users/kdf/go/pkg/mod/github.com/sijms/go-ora/[email protected]/data_set.go:94 +0xc5 Jul 30 12:23:50 : github.com/sijms/go-ora/v2.(*DataSet).load(0xc0000820a0, 0x1?) Jul 30 12:23:50 : C:/Users/kdf/go/pkg/mod/github.com/sijms/go-ora/[email protected]/data_set.go:78 +0x1a9 Jul 30 12:23:50 : github.com/sijms/go-ora/v2.(*defaultStmt).read(0xc000152300, 0xc0000820a0) Jul 30 12:23:50 : C:/Users/kdf/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:768 +0x17e Jul 30 12:23:50 : github.com/sijms/go-ora/v2.(*Stmt)._exec(0xc000152300, {0xc0001a63c0, 0x8, 0x4eb5f0?}) Jul 30 12:23:50 : C:/Users/kdf/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:2001 +0xa28 Jul 30 12:23:50 : github.com/sijms/go-ora/v2.(*Stmt).ExecContext(0xc000152300, {0xb7c800, 0xc0001c01c0}, {0xc0001a63c0, 0x8, 0x8}) Jul 30 12:23:50 : C:/Users/kdf/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:1275 +0x1d9 Jul 30 12:23:50 : github.com/sijms/go-ora/v2.(*Connection).ExecContext(0xc0003bbab8?, {0xb7c800, 0xc0001c01c0}, {0xac5032?, 0x4e8660?}, {0xc0001a63c0, 0x8, 0x8}) Jul 30 12:23:50 : C:/Users/kdf/go/pkg/mod/github.com/sijms/go-ora/[email protected]/connection.go:1066 +0x85 Jul 30 12:23:50 : database/sql.ctxDriverExec({0xb7c800?, 0xc0001c01c0?}, {0x7f17b0495bf8?, 0xc00022c280?}, {0x0?, 0x0?}, {0xac5032?, 0xc0000826b0?}, {0xc0001a63c0, 0x8, ...}) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/ctxutil.go:31 +0xd7 Jul 30 12:23:50 : database/sql.(*DB).execDC.func2() Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/sql.go:1675 +0x165 Jul 30 12:23:50 : database/sql.withLock({0xb7a9c0, 0xc000098630}, 0xc000082870) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/sql.go:3502 +0x82 Jul 30 12:23:50 : database/sql.(*DB).execDC(0x420a01?, {0xb7c800?, 0xc0001c01c0}, 0xc000098630, 0x3ed600?, {0xac5032, 0x8c}, {0xc0000836f8, 0x8, 0x8}) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/sql.go:1670 +0x24f Jul 30 12:23:50 : database/sql.(*DB).exec(0x0?, {0xb7c800, 0xc0001c01c0}, {0xac5032, 0x8c}, {0xc0000836f8, 0x8, 0x8}, 0x8?) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/sql.go:1655 +0xdb Jul 30 12:23:50 : database/sql.(*DB).ExecContext.func1(0xcf?) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/sql.go:1634 +0x4f Jul 30 12:23:50 : database/sql.(*DB).retry(0x18?, 0xc000082a68) Jul 30 12:23:50 : C:/sw/go1.21.6.windows-amd64/go/src/database/sql/sql.go:1538 +0x42 Jul 30 12:23:50 : database/sql.(*DB).ExecContext(0xa2bc80?, {0xb7c800?, 0xc0001c01c0?}, {0xac5032?, 0xaa9164?}, {0xc0000836f8?, 0xc0003ebee0?, 0xa?})
code:
ctx := context.Background()
call := "BEGIN PROCEDURE(:1,:2); END;"
stmt, err := db.DB.PrepareContext(ctx, call)
if err != nil {
log.Errorf("Error preparing statement: %v", err)
return resp, err
}
defer stmt.Close()
var FavResult go_ora.RefCursor
_, err = stmt.ExecContext(ctx, CustId, sql.Out{Dest: &FavResult })
if err != nil {
log.Errorf("Error executing statement: %v", err)
return resp, err
}
rows, err := FavResult .Query()
if err != nil {
log.Errorf("Error fetching rows : %v", err)
return resp, err
}
defer rows.Close()
var resp []models.respDTO
for rows.Next_() {
var fav models.FavDTO
err := rows.Scan(
&fav.Latitude,
&fav.Longitude,
)
if err != nil {
log.Errorf("Error scanning row: %v", err)
}
resp = append(resp , fav)
}
sometimes this error message also pops up
Jul 30 16:06:32 : 2024/07/30 16:06:32 TTC error: received code 6 during response reading Jul 30 16:06:32 systemd[1]: GO_Trans.service: Main process exited, code=exited, status=1/FAILURE Jul 30 16:06:32 systemd[1]: GO_tran.service: Failed with result 'exit-code'.
ran with -race and used WrapRefCursor
================== WARNING: DATA RACE Write at 0x00c00059e168 by goroutine 74: bufio.(*Reader).Read() C:/Program Files/Go/src/bufio/bufio.go:259 +0x77e github.com/sijms/go-ora/v2/network.(*Session).readAll() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:949 +0x165 github.com/sijms/go-ora/v2/network.(*Session).readPacketData() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:971 +0xa9 github.com/sijms/go-ora/v2/network.(*Session).readPacket() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:1009 +0x3e github.com/sijms/go-ora/v2/network.(*Session).read() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:797 +0xe4 github.com/sijms/go-ora/v2/network.(*Session).GetByte() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:1560 +0x204 github.com/sijms/go-ora/v2.(*defaultStmt).read() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:761 +0x20c github.com/sijms/go-ora/v2.(*Stmt)._exec() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:2001 +0x1887 github.com/sijms/go-ora/v2.(*Stmt).ExecContext() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:1275 +0x309 github.com/sijms/go-ora/v2.(*Connection).ExecContext() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/connection.go:1066 +0xc4 database/sql.ctxDriverExec() C:/Program Files/Go/src/database/sql/ctxutil.go:31 +0xea database/sql.(*DB).execDC.func2() C:/Program Files/Go/src/database/sql/sql.go:1675 +0x265 database/sql.withLock() C:/Program Files/Go/src/database/sql/sql.go:3502 +0xb6 database/sql.(*DB).execDC() C:/Program Files/Go/src/database/sql/sql.go:1670 +0x3a4 database/sql.(*DB).exec() C:/Program Files/Go/src/database/sql/sql.go:1655 +0x15a database/sql.(*DB).ExecContext.func1() C:/Program Files/Go/src/database/sql/sql.go:1634 +0xcf database/sql.(*DB).retry() C:/Program Files/Go/src/database/sql/sql.go:1538 +0x4a database/sql.(*DB).ExecContext() C:/Program Files/Go/src/database/sql/sql.go:1633 +0x193 database/sql.(*DB).Exec() C:/Program Files/Go/src/database/sql/sql.go:1647 +0x946 net/http.HandlerFunc.ServeHTTP() C:/Program Files/Go/src/net/http/server.go:2136 +0x47 main.accessControlMiddleware.func1() C:/Users/go/main.go:126 +0x4ae net/http.HandlerFunc.ServeHTTP() C:/Program Files/Go/src/net/http/server.go:2136 +0x47 github.com/gorilla/mux.(*Router).ServeHTTP() C:/Users/go/pkg/mod/github.com/gorilla/[email protected]/mux.go:212 +0x361 net/http.serverHandler.ServeHTTP() C:/Program Files/Go/src/net/http/server.go:2938 +0x2a1 net/http.(*conn).serve() C:/Program Files/Go/src/net/http/server.go:2009 +0xc24 net/http.(*Server).Serve.func3() C:/Program Files/Go/src/net/http/server.go:3086 +0x4f
Previous write at 0x00c00059e168 by goroutine 22: bufio.(*Reader).Read() C:/Program Files/Go/src/bufio/bufio.go:259 +0x77e github.com/sijms/go-ora/v2/network.(*Session).readAll() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:949 +0x165 github.com/sijms/go-ora/v2/network.(*Session).readPacketData() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:998 +0x474 github.com/sijms/go-ora/v2/network.(*Session).readPacket() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:1009 +0x3e github.com/sijms/go-ora/v2/network.(*Session).read() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:797 +0xe4 github.com/sijms/go-ora/v2/network.(*Session).GetByte() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/network/session.go:1560 +0x204 github.com/sijms/go-ora/v2.(*defaultStmt).read() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/command.go:761 +0x20c github.com/sijms/go-ora/v2.(*RefCursor)._query() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/ref_cursor.go:110 +0x12f github.com/sijms/go-ora/v2.(*RefCursor).Query() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/ref_cursor.go:132 +0x30a github.com/sijms/go-ora/v2.WrapRefCursor() C:/Users/go/pkg/mod/github.com/sijms/go-ora/[email protected]/connection.go:1092 +0x52 net/http.HandlerFunc.ServeHTTP() C:/Program Files/Go/src/net/http/server.go:2136 +0x47 main.accessControlMiddleware.func1() C:/Users/go/main.go:126 +0x4ae net/http.HandlerFunc.ServeHTTP() C:/Program Files/Go/src/net/http/server.go:2136 +0x47 github.com/gorilla/mux.(*Router).ServeHTTP() C:/Users/go/pkg/mod/github.com/gorilla/[email protected]/mux.go:212 +0x361 net/http.serverHandler.ServeHTTP() C:/Program Files/Go/src/net/http/server.go:2938 +0x2a1 net/http.(*conn).serve() C:/Program Files/Go/src/net/http/server.go:2009 +0xc24 net/http.(*Server).Serve.func3() C:/Program Files/Go/src/net/http/server.go:3086 +0x4f
Goroutine 74 (running) created at: net/http.(*Server).Serve() C:/Program Files/Go/src/net/http/server.go:3086 +0x86c net/http.(*Server).ListenAndServe() C:/Program Files/Go/src/net/http/server.go:2985 +0xbc main.main.func2() C:/Users/go/main.go:98 +0x164
Goroutine 22 (running) created at: net/http.(*Server).Serve() C:/Program Files/Go/src/net/http/server.go:3086 +0x86c net/http.(*Server).ListenAndServe() C:/Program Files/Go/src/net/http/server.go:2985 +0xbc main.main.func2() C:/Users/go/main.go:98 +0x164
solved this by adding mutex.Lock() in the function. I just need to know that is this a correct way or am I missing something?
still this issue happening even though i added mutex lock at the beginning of the function have anyone faced similar issue?
would you please test it for new v2.8.20
Hi @sijms Thanks for the response facing the below error after update Error executing statement: TTC error: received code 11 during response reading. Error executing statement: TTC error: received code 1 during response reading. Failed to execute statement: ORA-01002: fetch out of sequence. Error fetching rows: connection break due to context timeout. ORA-03146: invalid buffer length for TTC field.
Hi,
I also encounter the error when reading from an uninitialized REF CURSOR. If the connection is returned to the pool after this, further use of the connection will result in an error.
Steps to reproduce:
Execute a stored procedure returning a REF CURSOR.
Attempt to read from it, but the REF CURSOR is not initialized.
An error occurs (connection break due to context timeout).
The connection is returned to the pool, but it is now unusable.
Further attempts to use this connection lead to errors.
Expected behavior:
The connection should either be marked as bad and not returned to the pool, or closed after encountering such an error. This would prevent further errors and ensure that the application behaves as expected.
Thank you!
@firdavstoshev would you please point to the piece of code that produce the error or make PR I test the code on my local environment without errors