Skip to content

Load Npcap wpcap.dll lazily to avoid blocking upgrades on Windows#51716

Merged
samuelvl merged 2 commits into
elastic:mainfrom
samuelvl:fix-packetbeat-pcap-upgrade
Jul 9, 2026
Merged

Load Npcap wpcap.dll lazily to avoid blocking upgrades on Windows#51716
samuelvl merged 2 commits into
elastic:mainfrom
samuelvl:fix-packetbeat-pcap-upgrade

Conversation

@samuelvl

@samuelvl samuelvl commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

On Windows importing gopacket/pcap used to load wpcap.dll in the package init() (see elastic/gopacket#7).

When elastic-agent runs the collector in process mode, every collector process (not only packetbeat) loads wpcap.dll at startup:

PS C:\Windows\system32> tasklist /m wpcap.dll

Image Name                     PID Modules
========================= ======== ============================================
elastic-otel-collector.exe    1234 wpcap.dll
elastic-otel-collector.exe    5678 wpcap.dll
elastic-otel-collector.exe    9012 wpcap.dll

While any of these processes holds the DLL open, the packetbeat installer cannot replace wpcap.dll to upgrade Npcap.

Load wpcap.dll lazily instead of at package init so only packetbeat loads it and only when needed.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None. wpcap.dll is now loaded on demand instead of at startup. Packetbeat behaves the same but other beats no longer hold the DLL open.

How to test this PR locally

On Windows with an older Npcap already installed, run Packetbeat with the Network Traffic input plus other Beats. Packetbeat should upgrade Npcap and start capturing instead of failing with exit status 2.

Automated: mage systemTest on Windows runs TestWindowsNpcapInstaller, which now also verifies that a process only importing the capture code does not load wpcap.dll.

Related issues

@samuelvl samuelvl added bug Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Windows Platform Windows Platform Team in Security Solution windows backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches labels Jul 3, 2026
@botelastic botelastic Bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

Comment thread go.mod Outdated
@mergify

mergify Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b fix-packetbeat-pcap-upgrade upstream/fix-packetbeat-pcap-upgrade
git merge upstream/main
git push upstream fix-packetbeat-pcap-upgrade

@samuelvl samuelvl force-pushed the fix-packetbeat-pcap-upgrade branch from 5f3734b to 2ec4e64 Compare July 3, 2026 21:34
@github-actions

This comment has been minimized.

@samuelvl samuelvl force-pushed the fix-packetbeat-pcap-upgrade branch from 2ec4e64 to 63cf83b Compare July 3, 2026 21:40
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

TL;DR

The current Buildkite failure is a Metricbeat go vet compile error, not a Packetbeat/Npcap test failure. metricbeat/mb/module/runner_test.go:173 still passes a *logp.Logger to module.NewWrapper, whose current signature requires *beat.Info.

Remediation

  • Update metricbeat/mb/module/runner_test.go:173 to pass &beat.Info{Logger: logptest.NewTestingLogger(t, "")} as the third module.NewWrapper argument.
  • Validate with cd metricbeat && go test ./mb/module -run TestRunnerStop_ClientClosedAfterPublishGoroutine -count=1, then rerun make -C metricbeat check update/Buildkite.
Investigation details

Root Cause

go vet ./... fails while compiling the metricbeat/mb/module_test package. The failing call is:

metricbeat/mb/module/runner_test.go:173
m, err := module.NewWrapper(config, mb.Registry, logptest.NewTestingLogger(t, ""), beatmonitoring.NewMonitoring(), paths.New(), module.WithMetricSetInfo())

But metricbeat/mb/module/wrapper.go:93 defines NewWrapper as:

func NewWrapper(config *conf.C, r *mb.Register, info *beat.Info, monitoring beatmonitoring.Monitoring, p *paths.Path, options ...Option) (*Wrapper, error)

So the third argument must be a *beat.Info, matching nearby tests such as metricbeat/mb/module/wrapper_test.go:116.

Evidence

# github.com/elastic/beats/v7/metricbeat/mb/module_test
# [github.com/elastic/beats/v7/metricbeat/mb/module_test]
vet: mb/module/runner_test.go:173:51: cannot use logptest.NewTestingLogger(t, "") (value of type *logp.Logger) as *beat.Info value in argument to module.NewWrapper
Error: failed running go vet, please fix the issues reported: running "go vet ./..." failed with exit code 1

The PR diff shown for this run does not modify metricbeat/mb/module/runner_test.go, so this looks like a base-branch Metricbeat test compile break that this PR’s Buildkite run is surfacing, rather than a failure in the Packetbeat/Npcap changes.

Verification

I reproduced the same compile failure locally with:

cd metricbeat && go test ./mb/module -run TestRunner -count=1

The command failed with the same error:

mb/module/runner_test.go:173:51: cannot use logptest.NewTestingLogger(t, "") (value of type *logp.Logger) as *beat.Info value in argument to module.NewWrapper

Follow-up

The previous detective comment on this PR was for an earlier merge-conflict failure. This run has a different root cause and remediation.


What is this? | From workflow: PR Buildkite Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@samuelvl samuelvl force-pushed the fix-packetbeat-pcap-upgrade branch from 63cf83b to e0dda74 Compare July 6, 2026 13:07
@samuelvl samuelvl marked this pull request as ready for review July 6, 2026 16:16
@samuelvl samuelvl requested review from a team as code owners July 6, 2026 16:16
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform)

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform)

@mergify

mergify Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@samuelvl samuelvl merged commit 19d43cf into elastic:main Jul 9, 2026
254 checks passed
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport 9.5 9.4 9.3

@mergify

mergify Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

samuelvl added a commit that referenced this pull request Jul 9, 2026
…1716) (#51828)

(cherry picked from commit 19d43cf)

Co-authored-by: Samu <samuel.veloso@elastic.co>
samuelvl added a commit that referenced this pull request Jul 9, 2026
…1716) (#51829)

(cherry picked from commit 19d43cf)

Co-authored-by: Samu <samuel.veloso@elastic.co>
samuelvl added a commit that referenced this pull request Jul 9, 2026
…1716) (#51830)

(cherry picked from commit 19d43cf)

Co-authored-by: Samu <samuel.veloso@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches bug Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Windows Platform Windows Platform Team in Security Solution windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Packetbeat fails to upgrade on Windows when a newer Npcap version is available

2 participants