diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-09-08 14:21:38 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-09-08 16:55:55 -0400 |
commit | 4d410a5f047b5b4b55b2dcfc29d5264de695fe94 (patch) | |
tree | 6b81968e7d9bf0b15cd937823e69d7d558362ad0 /nslcd_server | |
parent | 7b8aefea056f995ee2d00a79c22277c09cda5363 (diff) |
nslcd_server: FIX: HandleRequest(): error handling
Instead of having a separate channel+goroutine for the backend, just call
.Write() right where we get results from the backend, but don't let an
error cause us to stop reading from the backend, an error should just cause
us to stop writing. This ensures that the backend now always has its
output chan drained; before if there were a write error, the backend chan
wouldn't get drained, and the resources never released.
Diffstat (limited to 'nslcd_server')
-rwxr-xr-x | nslcd_server/func_handlerequest.go.gen | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/nslcd_server/func_handlerequest.go.gen b/nslcd_server/func_handlerequest.go.gen index 40e00c0..d34db88 100755 --- a/nslcd_server/func_handlerequest.go.gen +++ b/nslcd_server/func_handlerequest.go.gen @@ -53,20 +53,15 @@ func HandleRequest(backend Backend, in io.Reader, out io.Writer, cred unix.Ucred } } }() - handleRequest(backend, in, out, cred) - return -} -func handleRequest(backend Backend, in io.Reader, out io.Writer, cred unix.Ucred) { var version int32 maybePanic(p.Read(in, &version)) if version != p.NSLCD_VERSION { - panic(p.NslcdError(fmt.Sprintf("Version mismatch: server=%#08x client=%#08x", p.NSLCD_VERSION, version))) + return p.NslcdError(fmt.Sprintf("Version mismatch: server=%#08x client=%#08x", p.NSLCD_VERSION, version)) } var action int32 maybePanic(p.Read(in, &action)) - ch := make(chan interface{}) switch action { $( while read -r request; do @@ -99,27 +94,25 @@ while read -r request; do ;; esac ) - _ch := backend.${request}(cred, req) - go func() { - defer close(ch) - for obj := range _ch { - ch <- obj + maybePanic(p.Write(out, p.NSLCD_VERSION)) + maybePanic(p.Write(out, action)) + ch := backend.${request}(cred, req) + for result := range ch { + if err == nil { + err = p.Write(out, p.NSLCD_RESULT_BEGIN) + } + if err == nil { + err = p.Write(out, result) } - }() + } + maybePanic(err) + maybePanic(p.Write(out, p.NSLCD_RESULT_END)) + return nil EOT done < "$requests" ) default: - close(ch) - panic(p.NslcdError(fmt.Sprintf("Unknown request action: %#08x", action))) - } - maybePanic(p.Write(out, p.NSLCD_VERSION)) - maybePanic(p.Write(out, action)) - - for result := range ch { - maybePanic(p.Write(out, p.NSLCD_RESULT_BEGIN)) - maybePanic(p.Write(out, result)) + return p.NslcdError(fmt.Sprintf("Unknown request action: %#08x", action)) } - maybePanic(p.Write(out, p.NSLCD_RESULT_END)) } EOF |