Golang, beego framework uses worm to connect DM database, and starts to report invalid memory address or nil point dereference under Linux
GOPATH=/home/wt207/go-space #gosetup
/home/wt207/go/bin/go build -o /tmp/___1go_build_main_go -gcflags all=-N -l /home/wt207/go-space/insight-client/main.go #gosetup
/home/wt207/GoLand-2021.1.3/plugins/go/lib/dlv/linux/dlv --listen=0.0.0.0:40223 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec /tmp/___1go_build_main_go --
API server listening at: [::]:40223
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xd34e4e]
goroutine 1 [running]:
gitee.com/chunanyong/dm.(*Properties).GetTrimString(0x0, 0x158d9c9, 0xc, 0x0, 0x0, 0x0, 0x0)
/home/wt207/go-space/pkg/mod/gitee.com/chunanyong/[email protected]/zv.go:80 +0x6e
gitee.com/chunanyong/dm.(*DmConnector).mergeConfigs(0xc000034600, 0x15b2b55, 0x28, 0x0, 0x0)
/home/wt207/go-space/pkg/mod/gitee.com/chunanyong/[email protected]/n.go:767 +0x274
gitee.com/chunanyong/dm.(*DmDriver).openConnector(0xc00015ce80, 0x15b2b55, 0x28, 0x0, 0x0, 0x0)
/home/wt207/go-space/pkg/mod/gitee.com/chunanyong/[email protected]/p.go:79 +0x105
gitee.com/chunanyong/dm.(*DmDriver).OpenConnector(0xc00015ce80, 0x15b2b55, 0x28, 0x0, 0x0, 0x0, 0x0)
/home/wt207/go-space/pkg/mod/gitee.com/chunanyong/[email protected]/p.go:63 +0x6d
database/sql.Open(0x157561c, 0x2, 0x15b2b55, 0x28, 0x0, 0x0, 0x0)
/home/wt207/go/src/database/sql/sql.go:771 +0x1cb
gitee.com/chunanyong/zorm.newDataSource(0xc00007fb00, 0x0, 0x0, 0x0)
/home/wt207/go-space/pkg/mod/gitee.com/chunanyong/[email protected]/dataSource.go:59 +0xdc
gitee.com/chunanyong/zorm.NewDBDao(0xc00007fb00, 0x0, 0x0, 0x0)
/home/wt207/go-space/pkg/mod/gitee.com/chunanyong/[email protected]/DBDao.go:70 +0x6b
main.main()
/home/wt207/go-space/insight-client/main.go:54 +0x91
Debugger finished with the exit code 0
The database connection configuration is as follows:
func main() {
//Custom zorm log output
//zorm.LogCallDepth = 4 //level of logging calls
//zorm.FuncLogError = myFuncLogError //function to record exception logs
//FuncLogPanic = myFuncLogPanic //logging panic log, default use ZormErrorLog implementation
//FuncPrintSQL = myFuncPrintSQL // function to print sql
//custom log output format, reassign FuncPrintSQL function
//SetFlags(log.LstdFlags)
//zorm.FuncPrintSQL = zorm.
//dbDaoConfig database configuration. Here is just a simulation, production should be reading configuration configuration file, construct DataSourceConfig
dbDaoConfig := zorm.DataSourceConfig{
//DSN database connection string
DSN: "dm://GO207:[email protected]:5236",
//DSN: ". /db/test.db",
//database driver name: mysql,postgres,oci8,sqlserver,sqlite3,dm,kingbase,aci and DBType correspond, handle databases with multiple drivers
DriverName: "dm",
// Database type (dialect judgment basis): mysql,postgresql,oracle,mssql,sqlite,dm,kingbase,shentong and DriverName correspond, processing database has more than one driver
DBType: "dm",
//MaxOpenConns Maximum number of database connections Default 50
MaxOpenConns: 50,
MaxIdleConns: 50, //MaxIdleConns: 50, //MaxIdleConns: 50
MaxIdleConns: 50,
//ConnMaxLifetimeSecond connection lifetime seconds. Default is 600 (10 minutes) after the connection is destroyed and rebuilt. MySQL default wait_timeout 28800 seconds (8 hours)
ConnMaxLifetimeSecond: 600,
//will use FuncPrintSQL to record SQL.
PrintSQL: true,
//DefaultTxOptions default configuration of transaction isolation level, default is nil
//DefaultTxOptions: nil,
//TxOptions{Isolation: sql.LevelDefault},
}
// Create dbDao according to dbDaoConfig, a database is executed only once, the first database to be executed is defaultDao, the subsequent zorm.xxx method, the default is used is defaultDao
var err error
dbDao, err = zorm.NewDBDao(&dbDaoConfig)
// Mark the test as failed
if err ! = nil {
fmt.Println("dm database connection failed:", err)
} else {
fmt.Println("dm database connection successful")
}
beego.Run()
}
reason
The reason is to get the system default DM_ Svc.conf
configuration file failed. According to the error prompt of the console, we can find the following method to get the DM of different systems_ SVC. Conf
configuration file.
if filePath == "" {
switch runtime.GOOS {
case "windows":
filePath = os.Getenv("SystemRoot") + "\\system32\\dm_svc.conf"
case "linux":
filePath = "/etc/dm_svc.conf"
default:
return
}
}
According to the default file path of windows system, find DM_ Open the SVC. Conf
configuration file and find the following
TIME_ZONE=(480)
LANGUAGE=(cn)
Solution
Creating DM in
configuration file, the content of which is similar to the /etc
path of Linux virtual machine_ SVC. Conf OS. Getenv ("systemroot") + "\ \ system32 \ \ DM of windows_ SVC. Conf "
configuration file can be consistent DM under
Path_ SVC. Conf
Read More:
- [Solved] Xshelln Connect to Local VM linux Error: Could not connect to ‘XXX.168.122.1‘ (port 22): Connection failed
- [Solved] Linux – error: cannot open Packages database in /var/lib/rpm
- [Solved] docker: Error response from daemon: OCI runtime create failed: container_linux.go:380
- [Solved] Web server failed to start. Port 8080 was already in use.
- Linux Error: Failed to connect to ::1: No route to the host
- Docker Startup Error: standard_init_linux.go:211: exec user process caused “no such file or directory”
- [Solved] Linux Error: Failed to start bean ‘webServerStartStop‘; nested exception is org.springframework.
- Linux Error: bind error: Address already in use [How to Solve]
- Prompt “entering emergency mode. Exit the shell to continue” if the Linux operating system does not start normally
- Linux Use dtc generate dtb Error: “FATAL ERROR: Unable to parse input tree“
- Linux First Install oracle Start Error [How to Solve]
- Linux Connect Error: network.service failed [How to Solve]
- [Solved] Linux — 9 — txt files are copied from windows to Linux and read error
- Win10 Start Linux error: Error: 0x800701bc WSL 2 [How to Solve]
- linux use sh execute source error [How to Solve]
- VScode connect Remote Linux Server Error: Resolver error: Error
- Grep: How to Find All the Files Containing a String in Linux
- [Solved] Linux Service Start Error: *.service: Main process exited, code=exited, status=203/EXEC
- Linux Execution Error “service mysqld start“error while loading shared libraries: libaio.so.1“
- How to Create Threads in Linux