简体   繁体   English

tls conn中的Golang恐慌阅读-仅在Linux上吗?

[英]Golang panic in tls conn Read - only on linux?

I'm using golang crypto/tls to process a custom line-oriented message protocol. 我正在使用golang crypto/tls处理自定义的面向行的消息协议。

This approach works fine on windows: 这种方法在Windows上效果很好:

var fullBuffer string

for {

    // If we're not connected, attempt reconnect
    if this.conn == nil {

        if this.IsSecure() {
            this.conn, err = tls.Dial("tcp", this.GetHostOnly(), nil)
        } else {
            this.conn, err = net.Dial("tcp", this.GetHostOnly())
        }

        if err == nil {
            // log and continue
        }
    }

    // Read from socket into our local buffer (blocking)
    if this.conn != nil {
        readBuff := make([]byte, 4096)
        nbytes, err = this.conn.Read(readBuff)
        if nbytes > 0 {
            fullBuffer += string(readBuff[0:nbytes])
        }
    }

Pretty straightforward - and it works fine on win64. 非常简单-在win64上运行良好。

But when i try to run it on Linux (debian 8 - both i386 and amd64 - both golang 1.5 native and 1.6 crosscompiled from windows) i get the following panic: 但是,当我尝试在Linux上运行它(debian 8-i386和amd64-都是从Windows进行golang 1.5本机和1.6交叉编译)时,我会遇到以下恐慌:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4ec8b4]

goroutine 8 [running]:
panic(0x8237780, 0x18522030)
    C:/Go/src/runtime/panic.go:464 +0x326
crypto/tls.(*Conn).Handshake(0x0, 0x0, 0x0)
    C:/Go/src/crypto/tls/conn.go:1023 +0x198
crypto/tls.(*Conn).Read(0x0, 0x18597000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
    C:/Go/src/crypto/tls/conn.go:922 +0x5e
mylib.(*MyConnection).worker(0x18512480)
    C:/gopath/src/mylib/mylib.go:342 +0x200

The Read call is failing because it's somehow passing nil to the TLS handshake. Read调用失败,因为它以某种方式将nil传递给TLS握手。

What's going wrong here? 这是怎么了

And, why is the problem isolated to linux? 而且,为什么这个问题只限于linux?

OK, linux builds are producing the error x509: certificate signed by unknown authority . 好的,Linux构建产生错误x509: certificate signed by unknown authority

But

  • the certificate is valid 证书有效

    • crypto/x509/root_unix.go looks in /etc/ssl/certs which is world-readable crypto/x509/root_unix.go/etc/ssl/certs查找,这是世界可读的
    • but openssl s_client is hanging on -showcerts -verify , pointing to some issue with my OS network configuration 但是openssl s_client挂在-showcerts -verify ,指出我的OS网络配置存在一些问题
  • for some reason the if block below is being entered regardless of the error 由于某种原因,无论错误如何,都将进入下面的if

    • but i was storing it as a net.Conn instead of a pointer, so it's not nil -able. 但我将其存储为net.Conn而不是指针,因此它不是nil -able。

Calling this solved, sorry for the noise. 称此为已解决,对不起您的声音。 Hopefully this debugging story helps someone else in the future 希望这个调试故事对以后的人有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM