Skip to content

fix(cmd): fix file descriptor leak from defer in loop#1154

Open
SVilgelm wants to merge 2 commits intovektra:v3from
SVilgelm:fix-file-close-leak
Open

fix(cmd): fix file descriptor leak from defer in loop#1154
SVilgelm wants to merge 2 commits intovektra:v3from
SVilgelm:fix-file-close-leak

Conversation

@SVilgelm
Copy link
Copy Markdown
Contributor

@SVilgelm SVilgelm commented Apr 2, 2026

Description

Extract file creation and writing into writeFile() helper so that defer file.Close() runs per-call instead of accumulating until Run() returns. With many mock files, the previous code could exhaust OS file descriptor limits.

  • Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Version of Go used when building/testing:

  • 1.25

How Has This Been Tested?

  1. go test ./... - no issues
  2. e2e/run_all.sh (fails on v3 as well)

RUNNING /Users/svunion/projects/mockery/e2e/test_missing_interface/run.sh
task: [mocks.generate.custom] go run .
2026-04-02T09:02:44.895693000-07:00 INF Starting mockery config-file=/Users/svunion/projects/mockery/e2e/test_missing_interface/.mockery.yml version=v0.0.0-dev
2026-04-02T09:02:44.895769000-07:00 INF Parsing configured packages... version=v0.0.0-dev
2026-04-02T09:02:45.008703000-07:00 INF Done parsing configured packages. version=v0.0.0-dev
2026-04-02T09:02:45.008739000-07:00 ERR interface not found in source. View the linked documentation for possible reasons why this might occur. docs-url=https://vektra.github.io/mockery/v0.0/faq/#error-interface-not-found-in-source interface=InterfaceDoesntExist package-path=github.com/vektra/mockery/v3/internal version=v0.0.0-dev
exit status 1
task: Failed to run task "mocks.generate.custom": exit status 1

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Extract file creation and writing into writeFile() helper so that
defer file.Close() runs per-call instead of accumulating until Run()
returns. With many mock files, the previous code could exhaust OS
file descriptor limits.
Copilot AI review requested due to automatic review settings April 2, 2026 16:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a potential OS file descriptor exhaustion in RootApp.Run() by ensuring file handles are closed per generated mock file rather than being deferred until the end of Run().

Changes:

  • Introduces a writeFile() helper to encapsulate create/write/close behavior.
  • Replaces the per-iteration defer file.Close() in the mock-generation loop with a call to writeFile().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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