mholt / caddy-webdav

WebDAV handler module for Caddy
Apache License 2.0
228 stars 24 forks source link

Issue with webdav RANGE requests #32

Closed arabcoders closed 1 year ago

arabcoders commented 1 year ago

Hello,

I tired using caddy webdav plugin as backend for the excellent rclone project, and indeed was working somewhat fine for small files, however i discovered that there is a problem related to the RANGE request and downloads failing for big files and having to-download that lead me to rclone issue #4459 comment by @ncw, it seems there is problem related to the range requests in webdav plugin causing the multipart download files to not send correct range the file real size is 875607573 or 836M. As far as i know single request downloads works fine.

2022/12/04 13:03:39 DEBUG : rclone: Version "v1.60.0" starting with parameters ["rclone" "copy" "caddy:/files/test.mp4" "." "-P" "-vvv"]
2022/12/04 13:03:39 DEBUG : Creating backend with remote "caddy:/files/test.mp4"
2022/12/04 13:03:39 DEBUG : Using config file from "/home/user/.config/rclone/rclone.conf"
2022/12/04 13:03:39 DEBUG : found headers:
2022/12/04 13:03:40 DEBUG : fs cache: adding new entry for parent of "caddy:/files/test.mp4", "caddy:files"
2022/12/04 13:03:40 DEBUG : Creating backend with remote "."
2022/12/04 13:03:40 DEBUG : fs cache: renaming cache item "." to be canonical "/home/user/tests"
2022-12-04 13:03:40 DEBUG : test.mp4: Need to transfer - File not found at Destination
2022-12-04 13:03:40 DEBUG : test.mp4: Starting multi-thread copy with 3 parts of size 278.375Mi
2022-12-04 13:03:40 DEBUG : test.mp4: multi-thread copy: stream 3/3 (583794688-875607573) size 278.294Mi starting
2022-12-04 13:03:40 DEBUG : test.mp4: multi-thread copy: stream 2/3 (291897344-583794688) size 278.375Mi starting
2022-12-04 13:03:40 DEBUG : test.mp4: multi-thread copy: stream 1/3 (0-291897344) size 278.375Mi starting
2022-12-04 13:04:00 DEBUG : test.mp4: multi-thread copy: stream 1/3 (0-291897344) size 278.375Mi finished
2022-12-04 13:04:00 DEBUG : test.mp4: multi-thread copy: stream 2/3 (291897344-583794688) size 278.375Mi finished
2022-12-04 13:04:17 DEBUG : test.mp4: multi-thread copy: stream 3/3 failed: multipart copy: wrote 875607573 bytes but expected to write 291812885
2022-12-04 13:04:17 ERROR : test.mp4: Failed to copy: multipart copy: wrote 875607573 bytes but expected to write 291812885
2022-12-04 13:04:17 ERROR : Attempt 1/3 failed with 1 errors and: multipart copy: wrote 875607573 bytes but expected to write 291812885
2022-12-04 13:04:18 DEBUG : test.mp4: Sizes differ (src 875607573 vs dst 1459402261)
2022-12-04 13:04:18 DEBUG : test.mp4: Starting multi-thread copy with 3 parts of size 278.375Mi
2022-12-04 13:04:18 DEBUG : test.mp4: multi-thread copy: stream 3/3 (583794688-875607573) size 278.294Mi starting
2022-12-04 13:04:18 DEBUG : test.mp4: multi-thread copy: stream 1/3 (0-291897344) size 278.375Mi starting
2022-12-04 13:04:18 DEBUG : test.mp4: multi-thread copy: stream 2/3 (291897344-583794688) size 278.375Mi starting
2022-12-04 13:04:33 DEBUG : test.mp4: multi-thread copy: stream 2/3 (291897344-583794688) size 278.375Mi finished
2022-12-04 13:04:33 DEBUG : test.mp4: multi-thread copy: stream 3/3 (583794688-875607573) size 278.294Mi finished
2022-12-04 13:04:33 DEBUG : test.mp4: multi-thread copy: stream 1/3 (0-291897344) size 278.375Mi finished
2022-12-04 13:04:33 DEBUG : test.mp4: Finished multi-thread copy with 3 parts of size 278.375Mi
2022-12-04 13:04:33 INFO  : test.mp4: Multi-thread Copied (replaced existing)
2022-12-04 13:04:33 ERROR : Attempt 2/3 succeeded
Transferred:        2.175 GiB / 2.175 GiB, 100%, 47.549 MiB/s, ETA 0s
Transferred:            1 / 1, 100%
Elapsed time:        53.3s
2022/12/04 13:04:33 INFO  :
Transferred:        2.175 GiB / 2.175 GiB, 100%, 47.549 MiB/s, ETA 0s
Transferred:            1 / 1, 100%
Elapsed time:        53.3s

2022/12/04 13:04:33 DEBUG : 4 go routines active
v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=
$ caddy list-modules
admin.api.load
admin.api.metrics
admin.api.pki
admin.api.reverse_proxy
caddy.adapters.caddyfile
caddy.config_loaders.http
caddy.listeners.http_redirect
caddy.listeners.tls
caddy.logging.encoders.console
caddy.logging.encoders.filter
caddy.logging.encoders.filter.cookie
caddy.logging.encoders.filter.delete
caddy.logging.encoders.filter.hash
caddy.logging.encoders.filter.ip_mask
caddy.logging.encoders.filter.query
caddy.logging.encoders.filter.regexp
caddy.logging.encoders.filter.rename
caddy.logging.encoders.filter.replace
caddy.logging.encoders.json
caddy.logging.writers.discard
caddy.logging.writers.file
caddy.logging.writers.net
caddy.logging.writers.stderr
caddy.logging.writers.stdout
caddy.storage.file_system
events
http
http.authentication.hashes.bcrypt
http.authentication.hashes.scrypt
http.authentication.providers.http_basic
http.encoders.gzip
http.encoders.zstd
http.handlers.acme_server
http.handlers.authentication
http.handlers.copy_response
http.handlers.copy_response_headers
http.handlers.encode
http.handlers.error
http.handlers.file_server
http.handlers.headers
http.handlers.map
http.handlers.metrics
http.handlers.push
http.handlers.request_body
http.handlers.reverse_proxy
http.handlers.rewrite
http.handlers.static_response
http.handlers.subroute
http.handlers.templates
http.handlers.tracing
http.handlers.vars
http.matchers.expression
http.matchers.file
http.matchers.header
http.matchers.header_regexp
http.matchers.host
http.matchers.method
http.matchers.not
http.matchers.path
http.matchers.path_regexp
http.matchers.protocol
http.matchers.query
http.matchers.remote_ip
http.matchers.vars
http.matchers.vars_regexp
http.precompressed.br
http.precompressed.gzip
http.precompressed.zstd
http.reverse_proxy.selection_policies.cookie
http.reverse_proxy.selection_policies.first
http.reverse_proxy.selection_policies.header
http.reverse_proxy.selection_policies.ip_hash
http.reverse_proxy.selection_policies.least_conn
http.reverse_proxy.selection_policies.random
http.reverse_proxy.selection_policies.random_choose
http.reverse_proxy.selection_policies.round_robin
http.reverse_proxy.selection_policies.uri_hash
http.reverse_proxy.transport.fastcgi
http.reverse_proxy.transport.http
http.reverse_proxy.upstreams.a
http.reverse_proxy.upstreams.multi
http.reverse_proxy.upstreams.srv
pki
tls
tls.certificates.automate
tls.certificates.load_files
tls.certificates.load_folders
tls.certificates.load_pem
tls.certificates.load_storage
tls.client_auth.leaf
tls.get_certificate.http
tls.get_certificate.tailscale
tls.handshake_match.remote_ip
tls.handshake_match.sni
tls.issuance.acme
tls.issuance.internal
tls.issuance.zerossl
tls.stek.distributed
tls.stek.standard

  Standard modules: 99

caddy.logging.encoders.formatted
caddy.logging.encoders.transform
dns.providers.cloudflare
http.handlers.webdav
layer4
layer4.handlers.echo
layer4.handlers.proxy
layer4.handlers.proxy_protocol
layer4.handlers.socks5
layer4.handlers.subroute
layer4.handlers.tee
layer4.handlers.throttle
layer4.handlers.tls
layer4.matchers.http
layer4.matchers.ip
layer4.matchers.proxy_protocol
layer4.matchers.socks4
layer4.matchers.socks5
layer4.matchers.ssh
layer4.matchers.tls
layer4.matchers.xmpp
layer4.proxy.selection_policies.first
layer4.proxy.selection_policies.ip_hash
layer4.proxy.selection_policies.least_conn
layer4.proxy.selection_policies.random
layer4.proxy.selection_policies.random_choose
layer4.proxy.selection_policies.round_robin
tls.handshake_match.alpn

  Non-standard modules: 28

  Unknown modules: 0
mholt commented 1 year ago

Interesting, thanks for the report!

I don't have time to look into this right now, but it's quite possibly something simple. Can you post your config and some instructions to reproduce as minimally as possible?

arabcoders commented 1 year ago

@mholt Thank you, while trying to make reproduceable sample, i noticed it was working fine with http, i remembered i have my servers behind Cloudflare, bypassing cloudflare for http/2 tests seems to be passing as well. re-activing cloudflare retrigger the problem.

So it seems the problem is cloudflare related and not caddy.

Sorry to bother you.

mholt commented 1 year ago

No problem, thanks for figuring that out!