Skip to content

Resource leak with p4java not closing RpcStreamOutputΒ #2

@brasky

Description

@brasky

Hello! My company uses the jenkins p4-plugin https://github.com/jenkinsci/p4-plugin and have been experiencing an issue on Windows where files are locked by java.exe which cause future builds on the same agent to fail. Here's an example from the jenkins pipeline:

image

I grabbed a memory dump and looked at it and noticed FileDescriptors with no references waiting for GC. If I force GC to run the build works fine, the file locks are gone. The parent of the FileDescriptor was:

image

So I started looking at p4java and have found multiple places where an RpcOutputStream is opened but never closed:.
Here it's only closed in the handling one exception but nowhere else:

Here it's just never closed:

RpcOutputStream outStream = this.fileCommands.getTempOutputStream(cmdEnv);

This is by no means an exhaustive list, but I wanted to make an issue before continuing to see what you thought. For now we are forced to run GC at the beginning of every build which is definitely not ideal. Would love some help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions