Skip to content

How to fix CLI0129E An attempt to allocate a handle failed because there are no more handles to allocate #203

@travelliu

Description

@travelliu

2023-03-07 at 15 08

Business logic .

Start a fixed number of coroutines and listen to chan. Then turn the query data into CSV Simulation program.

			db,err  := ConnectDatabase(ctx)
                         if err != nil {
                              return err
                         }
			// for i := 0; i < 10000; i++ {
			// 	s := fmt.Sprintf("create table test_more.table_%04v(id bigint,col1 varchar(10))",i)
			// 	db.Exec(s)
			// 	s = fmt.Sprintf("insert into test_more.table_%04v values (1,'col1')",i)
			// 	db.Exec(s)
			// }
			doSelect := func(i int64) {
				s := fmt.Sprintf("select id, col1 from test_more.table_%04v ",i)
				rows, err := db.Query(s)
				if err != nil {
					if strings.Contains(err.Error(),"undefined name") {
						return
					}
					panic(err)
				}
				// defer rows.Close()
				for rows.Next() {
					var (
						v  string
						id int
					)
					if err := rows.Scan(&id, &v); err != nil {
						panic(err)
					}
				}
				rows.Close()
				// fmt.Println(i)
			}
			taskChan := make(chan int64, 20)
			doTableDataTaskWorker := func() {
				for {
					select {
					case i, ok := <-taskChan:
						if !ok {
							return
						}
						doSelect(i)
					}
				}
			}
			wg := sync.WaitGroup{}
			parallel := 4
			wg.Add(parallel)
			for i := 0; i < parallel; i++ {
				go func(workNum int) {
					defer wg.Done()
					doTableDataTaskWorker()
				}(i)
			}
			go func() {
				for i := 0; i < 10000; i++ {
					taskChan <- int64(i)
				}
				close(taskChan)
			}()
			wg.Wait()
			db.Close()
  • os Version: macOS 13.2
  • cli-driver Version: 11.5.4
  • Db2 Server Version: v11.5.8.0
  • go Version:
go env Output:
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/travel/Library/Caches/go-build"
GOENV="/Users/travel/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/travel/Documents/Code/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/travel/Documents/Code/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/Cellar/go/1.19.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.19.4/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/travel/Documents/Code/go/src/gitlab.enmotech.com/enmotech/oracmd/go.mod"
GOWORK=""
CGO_CFLAGS="-I/Users/travel/Oracle_tools/db2client/include"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/Users/travel/Oracle_tools/db2client/lib"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k1/vqmqkz_s4gg5c0775rlv4g000000gn/T/go-build1067952203=/tmp/go-build -gno-record-gcc-switches -fno-common"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions