Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 戈朗在搜索博士后时惊慌失措_Postgresql_Go_Cookies_Server_Runtime Error - Fatal编程技术网

Postgresql 戈朗在搜索博士后时惊慌失措

Postgresql 戈朗在搜索博士后时惊慌失措,postgresql,go,cookies,server,runtime-error,Postgresql,Go,Cookies,Server,Runtime Error,因此,我有一个功能,我想添加到我正在编写的程序中。基本上,如果用户有cookie,说明他的用户名和密码是什么,它将在存储的postgres数据库中查找用户名和cookie的哈希值,如果我得到匹配,则返回肯定响应和JWT令牌(使用bcrypt哈希尽可能安全-存储哈希密码是否是一个好主意可能是另一个问题). 每次用户进入需要保存密码的页面时,都会向服务器发出此请求 我的问题是,偶尔我会得到以下信息 inside CookieLogin app_1 | search_userinfo_table

因此,我有一个功能,我想添加到我正在编写的程序中。基本上,如果用户有cookie,说明他的用户名和密码是什么,它将在存储的postgres数据库中查找用户名和cookie的哈希值,如果我得到匹配,则返回肯定响应和JWT令牌(使用bcrypt哈希尽可能安全-存储哈希密码是否是一个好主意可能是另一个问题).

每次用户进入需要保存密码的页面时,都会向服务器发出此请求

我的问题是,偶尔我会得到以下信息

inside CookieLogin
app_1  | search_userinfo_table started
db_1   | FATAL:  sorry, too many clients already
app_1  | 2018/08/26 16:22:25 pq: sorry, too many clients already
app_1  | 2018/08/26 16:22:25 http: panic serving 172.21.0.1:37304: pq: sorry, too many clients already
app_1  | goroutine 704 [running]:
app_1  | net/http.(*conn).serve.func1(0xc420156f00)
app_1  |    /usr/local/go/src/net/http/server.go:1721 +0xd0
app_1  | panic(0x6d63e0, 0xc420102c20)
app_1  |    /usr/local/go/src/runtime/panic.go:489 +0x2cf
app_1  | log.Panic(0xc4200438c0, 0x1, 0x1)
app_1  |    /usr/local/go/src/log/log.go:322 +0xc0
app_1  | github.com/patientplatypus/webserver/database.Search_userinfo_table(0xc42017f29d, 0xb, 0xc4201500c0, 0xc4200c22e0, 0xc420043a10)
app_1  |    /go/src/github.com/patientplatypus/webserver/database/search.go:18 +0x169
app_1  | github.com/patientplatypus/webserver/authentication.loginHandler(0xc42017f29d, 0xb, 0xc42017f2ba, 0x3, 0x899a80, 0xc420148460)
app_1  |    /go/src/github.com/patientplatypus/webserver/authentication/login.go:53 +0x39
app_1  | github.com/patientplatypus/webserver/authentication.CookieLogin(0x899a80, 0xc420148460, 0xc4203fc800)
app_1  |    /go/src/github.com/patientplatypus/webserver/authentication/login.go:35 +0x279
app_1  | net/http.HandlerFunc.ServeHTTP(0x75c658, 0x899a80, 0xc420148460, 0xc4203fc800)
app_1  |    /usr/local/go/src/net/http/server.go:1942 +0x44
app_1  | github.com/gorilla/mux.(*Router).ServeHTTP(0xc420052460, 0x899a80, 0xc420148460, 0xc4203fc800)
app_1  |    /go/src/github.com/gorilla/mux/mux.go:162 +0x101
app_1  | main.JWTHandler.func1(0x899a80, 0xc420148460, 0xc4203fc600)
app_1  |    /go/src/github.com/patientplatypus/webserver/main.go:34 +0x342
app_1  | net/http.HandlerFunc.ServeHTTP(0xc4200b12a0, 0x899a80, 0xc420148460, 0xc4203fc600)
app_1  |    /usr/local/go/src/net/http/server.go:1942 +0x44
app_1  | github.com/rs/cors.(*Cors).Handler.func1(0x899a80, 0xc420148460, 0xc4203fc600)
app_1  |    /go/src/github.com/rs/cors/cors.go:200 +0xe9
app_1  | net/http.HandlerFunc.ServeHTTP(0xc4200b12c0, 0x899a80, 0xc420148460, 0xc4203fc600)
app_1  |    /usr/local/go/src/net/http/server.go:1942 +0x44
app_1  | net/http.serverHandler.ServeHTTP(0xc42008a630, 0x899a80, 0xc420148460, 0xc4203fc600)
app_1  |    /usr/local/go/src/net/http/server.go:2568 +0x92
app_1  | net/http.(*conn).serve(0xc420156f00, 0x899fc0, 0xc4200506c0)
app_1  |    /usr/local/go/src/net/http/server.go:1825 +0x612
app_1  | created by net/http.(*Server).Serve
app_1  |    /usr/local/go/src/net/http/server.go:2668 +0x2ce
…然后golang客户端将崩溃,我将不得不手动重新启动。这是一个偶尔发生的错误,令人难以置信地沮丧,因为它使调试变得困难(为冗长的终端日志感到抱歉-我不确定错误何时会再次触发)

有人有什么建议吗?这是非duh解决方案的常见问题吗

谢谢

编辑:

据我所知,以下是令人不快的postgres搜索查询:

package data

import(
    "fmt"
    "log"
    _ "github.com/lib/pq"
)


func Search_userinfo_table(searchEmail string)(bool, string) {
    fmt.Println("search_userinfo_table started")
    rows, err1 := db.Query("SELECT * FROM userinfo")
    if err1 != nil {
        log.Panic(err1)
    }
    for rows.Next() {
        var email string
        var password string
        var regString string
        var regBool bool
        var uid int
        err2 := rows.Scan(&email, &password, &regString, &regBool, &uid)
        if err2 != nil {
            log.Panic(err2)
        }
        fmt.Println("email | password")
        fmt.Printf("%s | %s", email, password)
        if email == searchEmail{
            return false, password
        }
    }
    return true, ""
}

它返回用户是否在数据库中以及哈希密码。与一些人交谈,答案似乎是postgres每次读取时都会添加一个新连接,然后最终崩溃,但我希望它能够重用连接(尽管我认为这是自动发生的?)。无论如何,还有更多信息。

您缺少所需的
延迟行。Close()

*sql.Rows
的每个实例都有一个关联的连接。关闭rows实例时,关联的连接将被释放并放回池中(
*DB


另一方面,不关闭rows实例将导致其连接不可用。不释放连接将导致连接池尝试打开过多的新连接。

您缺少所需的
延迟行。Close()

*sql.Rows
的每个实例都有一个关联的连接。关闭rows实例时,关联的连接将被释放并放回池中(
*DB

另一方面,不关闭rows实例将导致其连接不可用。不释放连接将反过来导致连接池尝试打开一个或多个新连接