Skip to content

Cleanup threat intel resources - #109

Open
caffeinatedpixel wants to merge 1 commit into
499-close-conn-poolsfrom
503-threat-intel-close
Open

caffeinatedpixel wants to merge 1 commit into
499-close-conn-poolsfrom
503-threat-intel-close

Conversation

@caffeinatedpixel

Copy link
Copy Markdown
Contributor
  • Closes threat intel feed files opened during the threat intel sync process
  • Adds a timeout to the online feed request

Comment thread database/threat_intel.go
err = server.updateFeed(&entry, feeds[entry.Path].LastModified, feed, writer.WriteChannel)
if feed != nil {
if closeErr := feed.Close(); closeErr != nil {
return fmt.Errorf("failed to close threat intel feed after updating: %w", closeErr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to just log a warning here if the close fails instead of returning an error? If the cleanup fails we would be cancelling the whole import, and if updateFeed also errored this ends up returning the close error instead of the real one below. Would something like this work?

logger.Warn().Err(closeErr).Str("feed", entry.Path).Msg("[THREAT INTEL] Failed to close feed")

Comment thread database/threat_intel.go
if err = server.addNewFeed(path, &entry, feed, writer.WriteChannel); err != nil {
err = server.addNewFeed(path, &entry, feed, writer.WriteChannel)
if closeErr := feed.Close(); closeErr != nil {
return fmt.Errorf("failed to close threat intel feed after adding as new: %w", closeErr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as on line 192

checkThreatIntel(t, db)
}

func (d *ThreatIntelSuite) TestThreatIntelFeedFilesClosing() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a case where a feed fails partway through being read, kind of like the “Server Stops Partway Through The Feed” case you did in the database package, but for a file? Then check that the sync returns the error, opened still equals closed, and no writer goroutine is left over.

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

Successfully merging this pull request may close these issues.

2 participants