Skip to content

ftp: fix I/O timeout after long uploads - #5596

Merged
ivandeex merged 3 commits into
rclone:masterfrom
ivandeex:pr-ftp-timeout
Oct 21, 2021
Merged

ivandeex merged 3 commits into
rclone:masterfrom
ivandeex:pr-ftp-timeout

Conversation

@ivandeex

@ivandeex ivandeex commented Sep 11, 2021 •

Copy link
Copy Markdown
Member

What is the purpose of this change?

Uploading of large files via rclone frequently ends up with i/o timeout.

The investigation has revealed the following reasons:

  • jlaffaye/ftp makes control/data streams from a connection factory provided by rclone. This factory wraps standard go tcp streams in a code which safeguards against silently dead (lost without explicit TCP shutdown) network connections. It cancels dead streams after timeout but also resets the deadline timer after each read/write.
  • A typical FTP upload looks like this: client talks with ftp server on control stream, sets upload parameters, then creates one or more data streams and performs the upload (this can be long depending on file size).
  • Having finished with upload, client returns to the control stream and asks ftp server about upload results (here be dragons!), but while uploading on data stream progressed, the control stream timeout might have happened. The attempt to read status results in I/O timeout 💣

This patch makes rclone ftp client nudge the control connection right after a (probably long) upload has finished.

Depends on the upstream PR jlaffaye/ftp#231 which will provide new DialWithShutTimeout option and nudge control connections accordingly.

Please note that the fs/fshttp commit is not strictly required. I just wanted to make the code look a little bit cleaner on my eyes... 👀

The temporary DON'T MERGE commit will be removed after jlaffaye/ftp#231 gets merged. It just allows to verify changes in advance...

Was the change discussed in an issue or in the forum before?

Derivative manifestations of this problem were reported many times on rclone forum and tracker:

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@jcn50

jcn50 commented Sep 11, 2021 •

Copy link
Copy Markdown

Thanks a lot for that work! Looking forward to v1.57! You know this is also affecting the download~~

@jcn50

jcn50 commented Sep 11, 2021

Copy link
Copy Markdown

I think curl should be used as much as possible (for FTP for example) because it is the fastest & most reliable library~

@ivandeex

ivandeex commented Sep 16, 2021 •

Copy link
Copy Markdown
Member Author

Looking forward to v1.57!

Whether we have it in 1.57 depends primarily on how long it will take to accept the upstream patch. You should see the 1.57 label as a preliminary possibility.

You know this is also affecting the download.

The upstream patch introduces deadline nudging in a few places though the investigation started from the upload case.

I think curl should be used as much as possible (for FTP for example) because it is the fastest & most reliable library

You know curl is a C application / library. We support C bindings only on windows and macOS. On Unix rclone is distributed as a static golang application, so can't use it.

Moreover rclone uses custom TCP connections written in golang for features like bandwidth accounting / limiting or dead server elimination. By the way the latter feature is the cause of I/O timeout in the jlaffaye/ftp client. Here we keep it as it's useful, but polish.

And finally, my opinion. In future I'd prefer to get rid of any ftp dependencies and parse protocol messages directly in the backend, I think it can generally simplify code but I don't want to overhaul and retest now.

@ivandeex ivandeex modified the milestones: v1.57, v1.58 Sep 26, 2021
@ivandeex
ivandeex marked this pull request as draft September 30, 2021 07:42
@CarlosHartmann

CarlosHartmann commented Oct 2, 2021 •

Copy link
Copy Markdown

(Noob-alert!) Does this mean:

  1. That the fix is done?
  2. That it will be implemented in v. 1.58? Or possible earlier?

In any case, thanks a ton! I was getting desperate over this issue.

@ivandeex

ivandeex commented Oct 2, 2021

Copy link
Copy Markdown
Member Author

@CarlosHartmann
I am waiting for @jlaffaye to review jlaffaye/ftp#231. This can take long depending on how busy they are. Hopefully by 1.58.
If you need an immediate solution, use the latest iva release from https://github.com/ivandeex/rclone/releases. It's roughly equivalent to current rclone 1.57-beta plus my mount and FTP patches..

@ivandeex
ivandeex marked this pull request as ready for review October 5, 2021 17:53
@ivandeex

ivandeex commented Oct 7, 2021

Copy link
Copy Markdown
Member Author

This pull request can be long waiting for upstream. I created branch iva-ftp to have ready beta in advance.

@CarlosHartmann

Copy link
Copy Markdown

I should really do a thorough intro to git one day to understand all this. As I understand it now, you created an extra branch to have a beta version with fixed ftp right now. But it will take longer until it's part of the main branch?

I'll get the beta right now and test it first thing tomorrow in any case!

@CarlosHartmann

Copy link
Copy Markdown

I just uploaded 20 files all between 12GB and 35GB without one single error. At least for me, this is working perfectly! Let me know if there's a way to tip you some money. But in any case, you have my deepest gratitude for fixing the issue!

@ivandeex

ivandeex commented Oct 9, 2021 •

Copy link
Copy Markdown
Member Author

Glad it works for you :)
You can consider donating the project - https://rclone.org/donate/
Thank you

This was referenced Oct 16, 2021
@ivandeex
ivandeex force-pushed the pr-ftp-timeout branch 2 times, most recently from fd78f35 to d679118 Compare October 20, 2021 16:29
@ivandeex

Copy link
Copy Markdown
Member Author

@ncw
Now we've got https://github.com/rclone/ftp with latest fixes (the pull requests are still there waiting for jlaffaye)
so #5596 can be merged right for 1.57...
Requesting your review...

@ivandeex
ivandeex requested a review from ncw October 20, 2021 17:06
@ivandeex ivandeex modified the milestones: v1.58, v1.57 Oct 20, 2021
@ivandeex

ivandeex commented Oct 20, 2021 •

Copy link
Copy Markdown
Member Author

Note that previously this PR added a demonstration (negative) test which simulated the old buggy behavior, where backend didn't nudge control connection.
In practice it wasn't very reliable and depending on the test box capacity it failed to fail...
Instead it hung sporadically!
In the last commit I remove this demo test
keeping only the other one, the positive test that verifies absence of i/o timeout with nudging on.

@ivandeex

Copy link
Copy Markdown
Member Author

@ncw
Also note that I repoint the build to github.com/rclone/ftp via the replace go.mod directive.
This will let us quickly switch back when needed.
Do you agree?

@ivandeex

ivandeex commented Oct 20, 2021 •

Copy link
Copy Markdown
Member Author

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great - thank you :-)

Let's merge for 1.57

@ivandeex

Copy link
Copy Markdown
Member Author

@ivandeex
ivandeex merged commit 29c6c86 into rclone:master Oct 21, 2021
ivandeex added a commit that referenced this pull request Oct 21, 2021
@ivandeex
ivandeex deleted the pr-ftp-timeout branch October 21, 2021 11:18
@ismail

ismail commented Oct 22, 2021

Copy link
Copy Markdown

go.mod change breaks go install

; go install -v -ldflags="-s -w" github.com/rclone/rclone@master
go install: github.com/rclone/rclone@master (in github.com/rclone/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.
; go version
go version go1.17.2 darwin/arm64

@ivandeex

ivandeex commented Oct 23, 2021 •

Copy link
Copy Markdown
Member Author

@ismail

go.mod change breaks go install

; go install -v -ldflags="-s -w" github.com/rclone/rclone@master
go install: github.com/rclone/rclone@master (in github.com/rclone/[email protected]):
	The go.mod file for the module providing named packages contains one or
	more replace directives. It must not contain directives that would cause
	it to be interpreted differently than if it were the main module.
; go version
go version go1.17.2 darwin/arm64

Fixing go install requires me to refer to https://github.com/rclone/ftp directly from rclone go.mod, but

$ go get github.com/rclone/ftp@dev
go get: github.com/rclone/[email protected]: parsing go.mod:
        module declares its path as: github.com/jlaffaye/ftp
                but was required as: github.com/rclone/ftp

The fork was planned to be a temporary soft fork until the maintainer addresses our submitted patches. I don't want to replace all package directives around the fork source now turning it into hard fork. We plan considering this only in 5-7 months if the upstream project continues to ignore our requests.

For now you can use the below flow instead of go install:

$ git clone https://github.com/rclone/rclone
$ cd rclone
$ go install -v -ldflags="-s -w"

I am sorry about inconvenience.
cc @ncw

@ismail

ismail commented Oct 23, 2021

Copy link
Copy Markdown

Thanks for the explanation, workaround works for me.

lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FTP upload and download for big files (over 10GB) fails

5 participants