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

Panic when client receive redirect packet #23

Closed
rodrigoodhin opened this issue Nov 13, 2020 · 17 comments
Closed

Panic when client receive redirect packet #23

rodrigoodhin opened this issue Nov 13, 2020 · 17 comments

Comments

@rodrigoodhin
Copy link

rodrigoodhin commented Nov 13, 2020

Hi,

Aftter create a connection and open, I'm getting error at prepare statement.

My Connection function:

func Connect() (*sql.DB, error) {

	db, err := sql.Open("oracle", "oracle://USER:PASS@URL/SERVICE")

	if err != nil {
		return nil, err
	}

	return db, nil

}

My Work function:

func (t *TestData) GetDBValue() (err error) {

	//Connecting to Oracle DB here...
	db, err := oracle.Connect()
	if err != nil {
		return helpers.Error("It was not possible to connect to the database ", err)
	}
	defer db.Close()

	stmt, err := db.Prepare("SELECT * FROM DUAL WHERE 1 = :1")
	if err != nil {
		return helpers.Error("Error preparing query ", err)
	}
	defer stmt.Close()
	rows, err := stmt.Query(1)
	if err != nil {
		return helpers.Error("Error running query ", err)
	}
	defer rows.Close()
}

Error:

Error At this line: stmt, err := db.Prepare("SELECT * FROM DUAL WHERE 1 = :1")


runtime error: slice bounds out of range [:310] with capacity 16
runtime.gopanic
        /usr/local/go/src/runtime/panic.go:969
runtime.goPanicSliceAcap
        /usr/local/go/src/runtime/panic.go:106
github.com/sijms/go-ora/network.newRedirectPacketFromData
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/redirect_packet.go:41
github.com/sijms/go-ora/network.(*Session).readPacket
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:272
github.com/sijms/go-ora/network.(*Session).Connect
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:76
github.com/sijms/go-ora.(*Connection).Open
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:232
github.com/sijms/go-ora.(*oracleDriver).Open
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:79
database/sql.dsnConnector.Connect
        /usr/local/go/src/database/sql/sql.go:707
database/sql.(*DB).conn
        /usr/local/go/src/database/sql/sql.go:1294
database/sql.(*DB).prepare
        /usr/local/go/src/database/sql/sql.go:1482
database/sql.(*DB).PrepareContext
        /usr/local/go/src/database/sql/sql.go:1455
database/sql.(*DB).Prepare
        /usr/local/go/src/database/sql/sql.go:1472
myProject/steps.(*TestData).CreateDOs
        /home/rodrigo/myProject/steps/steps.go:178
reflect.Value.call
        /usr/local/go/src/reflect/value.go:475
reflect.Value.Call
        /usr/local/go/src/reflect/value.go:336
github.com/cucumber/godog/internal/models.(*StepDefinition).Run
        /home/rodrigo/myProject/vendor/github.com/cucumber/godog/internal/models/stepdef.go:159
github.com/cucumber/godog.(*suite).runStep
        /home/rodrigo/myProject/vendor/github.com/cucumber/godog/suite.go:138
github.com/cucumber/godog.(*suite).runSteps
        /home/rodrigo/myProject/vendor/github.com/cucumber/godog/suite.go:225
github.com/cucumber/godog.(*suite).runPickle
        /home/rodrigo/myProject/vendor/github.com/cucumber/godog/suite.go:284
github.com/cucumber/godog.(*runner).concurrent.func1
        /home/rodrigo/myProject/vendor/github.com/cucumber/godog/run.go:111
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1374

Thanks!

@sijms
Copy link
Owner

sijms commented Nov 13, 2020

if you receive redirect packet this means error

@sijms
Copy link
Owner

sijms commented Nov 13, 2020

this code work correct without error return result: X

conn, err := sql.Open("oracle", "oracle://user:pass@server:1521/service")
if err != nil {
	fmt.Println(err)
	return
}
defer conn.Close()
stmt, err := conn.Prepare("select * from dual where 1 = :1")
if err != nil {
	fmt.Println(err)
	return
}
defer stmt.Close()
results, err := stmt.Query(1)
if err != nil {
	fmt.Println(err)
	return
}
defer results.Close()
var temp string
for results.Next() {
	err = results.Scan(&temp)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("results: ", temp)
}
if err = results.Err(); err != nil {
	fmt.Println(err)
	return
}
return

@sijms
Copy link
Owner

sijms commented Nov 13, 2020

try to call db.Ping first before query to see if it is connected

@rodrigoodhin
Copy link
Author

Hi sijms,

Using your code and including only db.Ping, as you suggest, I still getting error message.

I've created the file test.go to validate the code that you've sent.

test.go

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/sijms/go-ora"
)

func main() {
	conn, err := sql.Open("oracle", "oracle://user:pass@server:1521/service")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer conn.Close()
	err = conn.Ping()
	if err != nil {
		fmt.Println(err)
		return
	}
	stmt, err := conn.Prepare("select * from dual where 1 = :1")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer stmt.Close()
	results, err := stmt.Query(1)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer results.Close()
	var temp string
	for results.Next() {
		err = results.Scan(&temp)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println("results: ", temp)
	}
	if err = results.Err(); err != nil {
		fmt.Println(err)
		return
	}
	return
}

Error:

panic: runtime error: slice bounds out of range [:315] with capacity 16

goroutine 1 [running]:
github.com/sijms/go-ora/network.newRedirectPacketFromData(0xc00001e4d0, 0xa, 0x10, 0xa)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/redirect_packet.go:41 +0x294
github.com/sijms/go-ora/network.(*Session).readPacket(0xc00000c1e0, 0x5f5be0, 0xc000001e00, 0x0, 0x0)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:272 +0xaf8
github.com/sijms/go-ora/network.(*Session).Connect(0xc00000c1e0, 0xc00000c1e0, 0xc)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:76 +0x29a
github.com/sijms/go-ora.(*Connection).Open(0xc00011e140, 0x3e, 0xc00011e140)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:232 +0x185
github.com/sijms/go-ora.(*oracleDriver).Open(0x82f180, 0x5ca80e, 0x3e, 0x0, 0x0, 0x203000, 0x200000)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:79 +0x77
database/sql.dsnConnector.Connect(...)
        /usr/local/go/src/database/sql/sql.go:707
database/sql.(*DB).conn(0xc00007edd0, 0x5f7040, 0xc00001e0f0, 0xc00000e001, 0x0, 0xc000055d00, 0x0)
        /usr/local/go/src/database/sql/sql.go:1294 +0x204
database/sql.(*DB).PingContext(0xc00007edd0, 0x5f7040, 0xc00001e0f0, 0x3e, 0xc00007edd0)
        /usr/local/go/src/database/sql/sql.go:799 +0x90
database/sql.(*DB).Ping(...)
        /usr/local/go/src/database/sql/sql.go:817
main.main()
        /home/rodrigo/myProject/test.go:16 +0x158
exit status 2

Oracle Version:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
"CORE	12.1.0.2.0	Production"
TNS for Linux: Version 12.1.0.2.0 - Production
NLSRTL Version 12.1.0.2.0 - Production

@fleshin
Copy link

fleshin commented Nov 13, 2020

Hi imrodrigoit, I faced similar issue but couldn't reproduce anymore (#6)
Are you running your server on Oracle RAC ?

@sijms
Copy link
Owner

sijms commented Nov 13, 2020

now the error in ping this means the error occur during connect
as fleshin comment I don't test the client with oracle RAC thus i didn't get redirectPacket

if you can help and print the data received from the server (redirect packet)
go to file network/redirect_packet.go and add line 28
fmt.Println(packetData)
and send me the print result to analyse the data and re-construct the code in this file to give the correct response

@rodrigoodhin
Copy link
Author

Hi,

@fleshin , I'm using RAC.
@sijms Follow the output after edit the file

[0 10 0 0 5 2 0 0 1 49]
panic: runtime error: slice bounds out of range [:315] with capacity 16

goroutine 1 [running]:
github.com/sijms/go-ora/network.newRedirectPacketFromData(0xc000108020, 0xa, 0x10, 0xa)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/redirect_packet.go:43 +0x33b
github.com/sijms/go-ora/network.(*Session).readPacket(0xc0000d2000, 0x5f5c20, 0xc000112000, 0x0, 0x0)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:272 +0xaf8
github.com/sijms/go-ora/network.(*Session).Connect(0xc0000d2000, 0xc0000d2000, 0xc)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:76 +0x29a
github.com/sijms/go-ora.(*Connection).Open(0xc0000cc140, 0x3e, 0xc0000cc140)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:232 +0x185
github.com/sijms/go-ora.(*oracleDriver).Open(0x82f180, 0x5ca80e, 0x3e, 0x0, 0x0, 0x203000, 0x200000)
        /home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:79 +0x77
database/sql.dsnConnector.Connect(...)
        /usr/local/go/src/database/sql/sql.go:707
database/sql.(*DB).conn(0xc00009ec30, 0x5f7080, 0xc0000a2000, 0xc0000ae001, 0x0, 0xc000050d00, 0x0)
        /usr/local/go/src/database/sql/sql.go:1294 +0x204
database/sql.(*DB).PingContext(0xc00009ec30, 0x5f7080, 0xc0000a2000, 0x3e, 0xc00009ec30)
        /usr/local/go/src/database/sql/sql.go:799 +0x90
database/sql.(*DB).Ping(...)
        /usr/local/go/src/database/sql/sql.go:817
main.main()
        /home/rodrigo/myProject/test.go:16 +0x158
exit status 2

@rodrigoodhin
Copy link
Author

Thank you so much for the update.
Now it's working!

@rodrigoodhin
Copy link
Author

Hi @sijms

Sorry, but I,ve tested using a DB that is not in RAC, but using a DB in RAC, I still getting error.
Using your code (hello_ora) to test, I'm getting this error:

panic: runtime error: slice bounds out of range [:315] with capacity 16

goroutine 1 [running]:
github.com/sijms/go-ora/network.newRedirectPacketFromData(0xc00010a3e0, 0xa, 0x10, 0xa)
/home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/redirect_packet.go:41 +0x294
github.com/sijms/go-ora/network.(*Session).readPacket(0xc00013c000, 0x5d99c0, 0xc000122480, 0x0, 0x0)
/home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:272 +0xaf8
github.com/sijms/go-ora/network.(*Session).Connect(0xc00013c000, 0xc00013c000, 0xc)
/home/rodrigo/myProject/vendor/github.com/sijms/go-ora/network/session.go:76 +0x29a
github.com/sijms/go-ora.(*Connection).Open(0xc000136140, 0x18, 0x0)
/home/rodrigo/myProject/vendor/github.com/sijms/go-ora/connection.go:232 +0x185
main.main()
/home/rodrigo/myProject/test.go:28 +0xad
exit status 2

@sijms
Copy link
Owner

sijms commented Nov 19, 2020

still

the problem is server send redirect packet 10 bytes long then send data packet that contains the redirect data.
I need to produce the condition to test the data received and fix the issue

@sijms
Copy link
Owner

sijms commented Nov 19, 2020

the redirect packet only available with oracle RAC
if you agree I will make some change to print data come form the server and you just test and give me the data structure only to update the code.

@rodrigoodhin
Copy link
Author

Yes, sure. No problem.

@sijms
Copy link
Owner

sijms commented Nov 20, 2020

I make a commit for test redirect packet as follow:
if pck.packet.length <= pck.packet.dataOffset
this means no data come in this packet and I need to read data again

after reading data I make 3 print

// all data returned from the server
fmt.Println("data returned: ", data) 

// redirect address
fmt.Println("redirect address: ", pck.redirectAddr)

// reconnect data
fmt.Println("reconnect data: ", pck.reconnectData)

@sijms sijms changed the title Cannot execute query Panic when client receive redirect packet Nov 21, 2020
@sijms
Copy link
Owner

sijms commented Nov 22, 2020

I think the issue is now solved
please try and tell me the result

@rodrigoodhin
Copy link
Author

Hi @sijms ,

Sorry the delay.
Follow the log after trying to connect.
I only change the IP, the HOST and the service name.

data returned: (ADDRESS=(PROTOCOL=TCP)(HOST=87.87.87.87)(PORT=1521))(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host.com:1521)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myService)(CID=(PROGRAM=/tmp/go-build664283631/b001/exe/go_ora)(HOST=rodrigo-bold)(USER=rodrigo))(SERVER=dedicated)(INSTANCE_NAME=myService)))
redirect address: (ADDRESS=(PROTOCOL=TCP)(HOST=87.87.87.87)(PORT=1521))
reconnect data: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host.com:1521)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myService)(CID=(PROGRAM=/tmp/go-build664283631/b001/exe/go_ora)(HOST=rodrigo-bold)(USER=rodrigo))(SERVER=dedicated)(INSTANCE_NAME=myService)))
Can't open connection: dial TCP: unknown network TCP
exit status 1

@sijms
Copy link
Owner

sijms commented Nov 23, 2020

Bug fixed
I make TCP lowercase to bypass this error

@rodrigoodhin
Copy link
Author

Hi @sijms ,

Thank You so much for your help. Now it's working!

data returned: (ADDRESS=(PROTOCOL=TCP)(HOST=87.87.87.87)(PORT=1521))(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host.com:1521)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myService)(CID=(PROGRAM=/tmp/go-build017102808/b001/exe/testGoOra)(HOST=rodrigo-bold)(USER=rodrigo))(SERVER=dedicated)(INSTANCE_NAME=myService2)))
redirect address: (ADDRESS=(PROTOCOL=TCP)(HOST=87.87.87.87)(PORT=1521))
reconnect data: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=host.com:1521)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myService)(CID=(PROGRAM=/tmp/go-build017102808/b001/exe/testGoOra)(HOST=rodrigo-bold)(USER=rodrigo))(SERVER=dedicated)(INSTANCE_NAME=myService)))

Successfully connected.

X

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

3 participants