Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: send on closed channel #8

Closed
zealws opened this issue Aug 13, 2014 · 3 comments
Closed

panic: runtime error: send on closed channel #8

zealws opened this issue Aug 13, 2014 · 3 comments

Comments

@zealws
Copy link

zealws commented Aug 13, 2014

I'm building a web-application that uses an LDAP server for authentication.

All the server needs to do is login using the LDAP server, no authorizations are made beyond that.

When I use the library to login once, it works fine, however, on a second try, it will panic.

A very minimal example that reproduces this problem is:

package main

import (
    "fmt"
    "github.com/mmitton/ldap"
    "log"
)

const (
    ADDR   = "WWWW"
    DOMAIN = "XXXX"
    USER   = "YYYY"
    PASS   = "ZZZZ"
)

func main() {
    fmt.Println("Try 1...")
    doLDAP()

    fmt.Println("\nTry 2...")
    doLDAP()
}

func doLDAP() {
    conn, err := ldap.Dial("tcp", ADDR)
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()

    fmt.Println("Connected successfully")

    err = conn.Bind(DOMAIN+"\\"+USER, PASS)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Logged in successfully")
}

Note that the constants are modified to working values for the LDAP server I am using.

The output is:

Try 1...
Connected successfully
Logged in successfully

Try 2...
closeAllChannels
panic: runtime error: send on closed channel

goroutine 25 [running]:
runtime.panic(0x5cd8e0, 0x71b19e)
    /tmp/go/src/pkg/runtime/panic.c:279 +0xf5
github.com/mmitton/ldap.func·003()
    /home/zeal/go/src/github.com/mmitton/ldap/conn.go:299 +0x4c
created by github.com/mmitton/ldap.(*Conn).sendProcessMessage
    /home/zeal/go/src/github.com/mmitton/ldap/conn.go:299 +0xa0
@sivel
Copy link

sivel commented Aug 14, 2014

I can confirm this as well. Everything works well up until the point when Close is called in my tests.

@sivel
Copy link

sivel commented Aug 14, 2014

FWIW, It looks like someone else has this fixed in their fork:

vanackere@3f715a8

@zealws
Copy link
Author

zealws commented Aug 15, 2014

FWIW, I wound up using cgo and openldap. Not quite as straight-forward but far more reliable.

I may open source the code I wrote in the future, but it's hard to write automated tests for an LDAP library since it requires posting test account credentials to GitHub.

vanackere pushed a commit to vanackere/ldap that referenced this issue Feb 24, 2015
Do not set conn to nil when closing
@mmitton mmitton closed this as completed Sep 28, 2017
mark-rushakoff referenced this issue in mark-rushakoff/ldapserver Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants