Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURLOPT_SEEKFUNCTION not called with CURLFORM_STREAM #768

Closed
ajfouts opened this Issue Apr 16, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@ajfouts
Copy link

ajfouts commented Apr 16, 2016

I did this

I'm using libcurl to POST form data using a FILE* with the CURLFORM_STREAM option of curl_formadd(). I've noticed that if the connection drops at just the right time, the POST is reattempted without the data from the file. It seems like the file stream position isn't getting reset to the beginning of the file. I found the CURLOPT_SEEKFUNCTION option and set that with a function that performs an fseek() on the FILE*. However, setting that didn't seem to fix the issue or even get called.

It seems like Curl_retry_request() has to get hit so that Curl_readrewind() is called (at least for my scenario). When Curl_readrewind() is called, the current logic prevents the CURLOPT_SEEKFUNCTION from getting called with a CURLFORM_STREAM.

I've attached a test client & server that's the closest I could get to the scenario I'm facing. Since it's a race condition whether or not the seek function is needed (depends on when the TCP session ends), it takes a lot of cycles of the test client to get the issue to occur. However, on my PC (Ubuntu 14.04 with an AMD Phenom II X4 B55 @ 3.2 GHz), I can get the issue to occur every time with the current number of test cycles set in the client.

curlform_stream_seek.tar.gz

I expected the following

I expected either Curl_readrewind() to seek the FILE* to the beginning automatically or for CURLOPT_SEEKFUNCTION to be called so I could seek the FILE* myself.

curl/libcurl version

curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP 

operating system

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty

@bagder bagder added the HTTP label Apr 20, 2016

@bagder

This comment has been minimized.

Copy link
Member

bagder commented Apr 20, 2016

Makes sense. Tried to patch this?

@bagder bagder closed this in ac09c42 Aug 2, 2016

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.