Skip to content

Close file connection in labkey.webdav.put - #132

Open
bbimber wants to merge 3 commits into
LabKey:developfrom
bbimber:fb_close_connections
Open

bbimber wants to merge 3 commits into
LabKey:developfrom
bbimber:fb_close_connections

Conversation

@bbimber

@bbimber bbimber commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Hi @cnathe and @labkey-klum: this is a small issue I noticed. Apparently httr does not always close open connections when uploading files. You can see this by trying to use labkey.webdav.put(), and then running "showConnections(all = TRUE)". This change should make labkey.webdav.put() clean up after itself.

According to google, httr2 is better about this. Migrating to httr2 probably wouldnt be that hard, but it would require some more updates across Rlabkey.

@cnathe

cnathe commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Ben, I verified locally that, as you mentioned, we have a leaked connection after the labkey.webdav.put. However, I applied your change locally and it results in the following error (and the connection still looks to be open):

Error in UseMethod("close") : 
  no applicable method for 'close' applied to an object of class "form_file"

I'm looking into other approaches to close the connection.

@bbimber

bbimber commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Odd - let me look into this.

@bbimber

bbimber commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@cnathe: i have a more elegant solution to this. will push here later this morning.

@bbimber

bbimber commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@cnathe, my last commit takes a different approach. I found this through gemini, and the corresponding stackoverflow post is in the comments. I did basic testing locally and this appears to solve the failure to close the connection. I dont think I'm able to kick off automated tests; however, those tests should do a good job of validating whether this solution preserves expected behaviors.

@cnathe

cnathe commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@bbimber I pulled down these changes locally and tested. This does take care of the leaked connection, but it ends up changing what gets store on the server for me. A WebDAV PUT saves the whole request body as the file, so the multipart wrapper ends up in the file. I tested against a local server and got this result for a text file that just had "hello" in the file content:

Screenshot 2026-11-11 at 6 23 36 PM

@bbimber

bbimber commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

OK, I will look into this closer tomorrow.

@bbimber

bbimber commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @cnathe:

Thank you for your patience on this. I just tested my last commit more completely and this solution, while not especially elegant, does seem to work. You can test using setDebugMode(TRUE):

write('Testing5', file = 'Test.txt')
labkey.setDebugMode(TRUE)
labkey.webdav.put(
  localFile = 'Test.txt',
  baseUrl = 'https://prime-seq.ohsu.edu',
  folderPath = 'Labs/Bimber',
  remoteFilePath = 'Test.txt'
)
showConnections(all = TRUE)

@cnathe

cnathe commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Ben, sorry for the delay. I haven't had a chance to get back to this yet and test out the latest solution. I'll try to get to that soon and get back to you.

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