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

fix: eagerly closes transactions when needed. #18

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,18 @@ func handleRequest(req api.Request, res api.Response) (next bool, reqCtx uint32)

// Early return, Coraza is not going to process any rule
if tx.IsRuleEngineOff() {
return true, 0
next = true
tx.Close()
return
}

defer func() {
if tx.IsInterrupted() {
// We run phase 5 rules and create audit logs (if enabled)
tx.ProcessLogging()
}

if !next {
// we remove temporary files and free some memory
if err := tx.Close(); err != nil {
tx.DebugLogger().Error().Err(err).Msg("Failed to close the transaction")
Expand Down Expand Up @@ -204,7 +209,7 @@ func handleRequest(req api.Request, res api.Response) (next bool, reqCtx uint32)
it = tx.ProcessRequestHeaders()
if it != nil {
handleInterruption(it, res)
return false, 0
return
}

if tx.IsRequestBodyAccessible() {
Expand All @@ -213,24 +218,26 @@ func handleRequest(req api.Request, res api.Response) (next bool, reqCtx uint32)
// regular flow.
it, _, err := tx.ReadRequestBodyFrom(readWriterTo{req.Body()})
if err != nil {
return false, 0
tx.DebugLogger().Error().Err(err).Msg("Failed to read request body")
return
}

if it != nil {
handleInterruption(it, res)
return false, 0
return
}
}

var err error
it, err = tx.ProcessRequestBody()
if err != nil {
return false, 0
tx.DebugLogger().Error().Err(err).Msg("Failed to process request body")
return
}

if it != nil {
handleInterruption(it, res)
return false, 0
return
}

reqCtx = rand.Uint32()
Expand Down
Loading