Skip to content

Commit

Permalink
when error, end requests with FCGI_ABORT_REQUEST
Browse files Browse the repository at this point in the history
  • Loading branch information
yookoala committed Feb 8, 2018
1 parent 2be5b56 commit d0c2832
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 14 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func (c *client) ReleaseID(reqID uint16) {
// writeRequest writes params and stdin to the FastCGI application
func (c *client) writeRequest(req *Request) (err error) {

// end request whenever the function block ends
defer func() {
if err != nil {
// abort the request if there is any error
// in previous request writing process.
c.conn.writeAbortRequest(req.ID)
return
}
}()

// write request header with specified role
err = c.conn.writeBeginRequest(req.ID, req.Role, 0)
if err != nil {
Expand All @@ -109,15 +119,15 @@ func (c *client) writeRequest(req *Request) (err error) {
if err == io.EOF {
err = nil
} else if err != nil {
break
return
}
if count == 0 {
break
}

err = c.conn.writeRecord(typeStdin, req.ID, p[:count])
if err != nil {
break
return
}
}
}
Expand All @@ -132,15 +142,15 @@ func (c *client) writeRequest(req *Request) (err error) {
if err == io.EOF {
err = nil
} else if err != nil {
break
return
}
if count == 0 {
break
}

err = c.conn.writeRecord(typeData, req.ID, p[:count])
if err != nil {
break
return
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions fcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func (c *conn) writeEndRequest(reqID uint16, appStatus int, protocolStatus uint8
return c.writeRecord(typeEndRequest, reqID, b)
}

func (c *conn) writeAbortRequest(reqID uint16) error {
return c.writeRecord(typeAbortRequest, reqID, nil)
}

func (c *conn) writePairs(recType recType, reqID uint16, pairs map[string]string) error {
w := newWriter(c, recType, reqID)
b := make([]byte, 8)
Expand Down

0 comments on commit d0c2832

Please sign in to comment.