Using Go wrapper, a fatal error or signal handled by YottaDB does not allow Go a cleanup opportunity
Final Release Note
Description
@zapkub sent us this issue as described below. Basically, the first version of the wrapper still had YottaDB controlling all the signals and if it detected a fatal error, it died pretty much then and there not returning to Go or otherwise giving a Go main program a chance at doing its own handling and cleanup. Here is the original description from @zapkub -
During the implementation of YottaDB as the database layer. I found that every time our application access the nil pointer the YottaDB process is crashing without any panic from Go itself.
Reproduce
- Execute YottaDB operation
- Access nil pointer object somewhere
- Entire application also include main thread has been crashed by YottaDB even there is recovery defer on the code
type A struct {
S string
}
func main() {
err := yottadb.SetValE(yottadb.NOTTP, nil, "something", "TEST", []string{"0001"})
if err != nil {
panic(err)
}
defer func() {
if r := recover(); r != nil {
fmt.Println("panic recovery!")
fmt.Println(r)
}
}()
var a *A
fmt.Println(a.S)
}
Result
%YDB-F-KILLBYSIGSINFO1, YottaDB process 10589 has been killed by a signal 11 at address 0x00000000004960F1 (vaddr 0x0000000000000008)
%YDB-F-SIGMAPERR, Signal was caused by an address not mapped to an object
Expectation
I expect our defer would work and this is what I have found how to make it work as I expect.
type A struct {
S string
}
func main() {
err := yottadb.SetValE(yottadb.NOTTP, nil, "something", "TEST", []string{"0001"})
if err != nil {
panic(err)
}
yottadb.Exit()
defer func() {
if r := recover(); r != nil {
fmt.Println("panic recovery!")
fmt.Println(r)
}
}()
var a *A
fmt.Println(a.S)
}
Result
panic recovery!
runtime error: invalid memory address or nil pointer dereference
From the screen shot above I have to call yottadb.Exit()
then everything will work as it is.
Question
- Should I call
Exit()
everytime after I execute the operation? - If not how I can handle this problem?
- If I should how to continue the yotta wrapper after I call
Exit()
Draft Release Note
The YottaDB Go wrapper now allows Go programs to handle fatal errors by doing a panic in the wrapper if a fatal signal is received. This is facilitated by changes in both the wrapper [#25 (closed)] and in YottaDB [YottaDB/DB/YDB#561 (closed)] to let Go do all signal handling and notify YottaDB that signals have occurred instead of the other way around. Previously, Go would not know a signal had occurred as the process would just die.