Repository navigation
Description
Syncing large files with the 2.1.1 (build 3107) client on OSX against ownCloud 9.0.2 on a slowish 384KB/s link I'm getting an "expected filesize 5242880 got 0" exception on about 5% of the chunk uploads. I've added some additional logging to OC\Files\View::file_put_contents() (see owncloud.log below) and it appears that apache is receiving the file chunk contents OK, ownCloud is writing the contents to the filesystem cache OK, but the chunk files are occasionally disappearing from the filesystem before OC_FileChunking::store() returns.
Any pointers on how to debug this gratefully received. On the assumption that the underlying filesystem isn't randomly losing files, my working hypothesis is that the cache is occasionally clearing up chunk files too aggressively while they're still being written.
Also, I'm aware of #9832 but that issue seems a mess of various problems, and of #11778 but this seems to be a different problem. Could be related to owncloud/client#4421.
Steps to reproduce
- Upload 6 100MB files with the ownCloud sync client over a slowish link.
Expected behaviour
Files sync OK.
Actual behaviour
Client reports "Error download https://xxx/xxx-chunking-xxx-y-z - server replied: Bad Request (expected filesize 5242880 got 0)"
Server configuration
Operating system: Linux
Web server: Apache 2.4.16
Database: MariaDB 10.1.14
PHP version: 5.5.32
ownCloud version: 9.0.2.2
Updated from an older ownCloud or fresh install: Updated incrementally from 5.0.7
Where did you install ownCloud from: https://download.owncloud.org/community/owncloud-9.0.2.zip
Signing status (ownCloud 9.0 and above):
No errors have been found.
List of activated apps:
Files
Gallery
Contacts
Calendar
The content of config/config.php:
<?php
$CONFIG = array (
'debug' => false,
'instanceid' => '51b4613a9b05a',
'passwordsalt' => 'Redacted',
'datadirectory' => '/home/marginal/owncloud-data',
'dbtype' => 'mysql',
'dbdriveroptions' =>
array (
1002 => 'SET wait_timeout = 3600',
),
'version' => '9.0.2.2',
'dbname' => 'marginal_owncloud',
'dbhost' => 'localhost',
'dbtableprefix' => 'oc_',
'dbuser' => 'Redacted',
'dbpassword' => 'Redacted',
'installed' => true,
'forcessl' => true,
'logfile' => '/home/marginal/owncloud.log',
'loglevel' => 0,
'log_rotate_size' => 67108864,
'maintenance' => false,
'theme' => '',
'trusted_domains' =>
array (
0 => 'Redacted',
),
'secret' => 'Redacted',
'share_folder' => '/Shared',
'forceSSLforSubdomains' => true,
'trashbin_retention_obligation' => 'auto',
);
Are you using external storage, if yes which one: Local
Are you using encryption: No
Are you using an external user-backend, if yes which one: None
Client configuration
Browser: Firefox 46.0.1
Operating system: OSX 10.10.5
Logs
Web server access log
x.x.x.x - - [17/May/2016:00:30:19 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-2 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:08 +0200] "GET /ocs/v1.php/cloud/activity?page=0&pagesize=100&format=json HTTP/1.1" 200 242 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:30:19 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-0 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:30:19 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-1 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:20 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 374 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:29 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:08 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-3 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:52 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 374 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:09 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-4 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:32:02 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:39 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-6 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:32:27 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 374 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:32:04 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-7 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:32:34 +0200] "PROPFIND /remote.php/webdav/ HTTP/1.1" 207 416 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:31:09 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-5 HTTP/1.1" 201 - "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
x.x.x.x - - [17/May/2016:00:32:06 +0200] "PUT /remote.php/webdav/Test/100M-2-chunking-1949736465-20-8 HTTP/1.1" 400 225 "-" "Mozilla/5.0 (Macintosh) mirall/2.1.1"
ownCloud log (data/owncloud.log)
{"reqId":"VzpJ@23JklEAADcNxJsAAAAG","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-2.YQIY9G9r9RWnP7YS.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:31:06+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-2","user":"xxx"}
{"reqId":"VzpJ@23JklEAADVGWzcAAAAM","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-0.5MiXMy0jYPhWsfQG.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:31:07+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-0","user":"xxx"}
{"reqId":"VzpJ@23JklEAADRc0bsAAAAD","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-1.JxhlUUjsdiqlImLV.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:31:07+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-1","user":"xxx"}
{"reqId":"VzpKLG3JklEAADpXFl4AAAAI","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-3.9caCvTHfJ9mRqU9Z.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:31:37+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-3","user":"xxx"}
{"reqId":"VzpKLW3JklEAADbZQCoAAAAC","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-4.g8dA06k5JAF1iUzp.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:32:00+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-4","user":"xxx"}
{"reqId":"VzpKS23JklEAADhbAwwAAAAJ","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-6.3YH71eRiLUiVjh9C.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:32:04+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-6","user":"xxx"}
{"reqId":"VzpKZG3JklEAADnhLgIAAAAB","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-7.bmRfooGP900enSbt.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:32:28+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-7","user":"xxx"}
{"reqId":"VzpKLW3JklEAADcNxJ4AAAAG","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-5.2a6iZC56JUVnROmJ.part: exists: 1, readable: 1, size: 5242880","level":1,"time":"2016-05-16T22:32:37+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-5","user":"xxx"}
{"reqId":"VzpKZm3JklEAACfcAz8AAAAF","remoteAddr":"x.x.x.x","app":"PHP","message":"filesize(): stat failed for \/home\/marginal\/owncloud-data\/xxx\/cache\/100M-2-chunking-1949736465-8.adjGuN5SCj567wO6.part at \/home\/marginal\/public_html\/lib\/private\/files\/storage\/local.php#142","level":3,"time":"2016-05-16T22:32:53+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-8","user":"xxx"}
{"reqId":"VzpKZm3JklEAACfcAz8AAAAF","remoteAddr":"x.x.x.x","app":"file_put_contents","message":"Wrote 5242880 bytes from Resource id #320 to cache\/100M-2-chunking-1949736465-8.adjGuN5SCj567wO6.part: exists: 0, readable: 0, size: 0","level":1,"time":"2016-05-16T22:32:53+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-8","user":"xxx"}
{"reqId":"VzpKZm3JklEAACfcAz8AAAAF","remoteAddr":"x.x.x.x","app":"webdav","message":"Exception: {\"Message\":\"HTTP\\\/1.1 400 expected filesize 5242880 got 0\",\"Exception\":\"Sabre\\\\DAV\\\\Exception\\\\BadRequest\",\"Code\":0,\"Trace\":\"#0 \\\/home\\\/marginal\\\/public_html\\\/apps\\\/dav\\\/lib\\\/connector\\\/sabre\\\/file.php(103): OCA\\\\DAV\\\\Connector\\\\Sabre\\\\File->createFileChunked(Resource id #320)\\n#1 \\\/home\\\/marginal\\\/public_html\\\/apps\\\/dav\\\/lib\\\/connector\\\/sabre\\\/directory.php(134): OCA\\\\DAV\\\\Connector\\\\Sabre\\\\File->put(Resource id #320)\\n#2 \\\/home\\\/marginal\\\/public_html\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(1036): OCA\\\\DAV\\\\Connector\\\\Sabre\\\\Directory->createFile('100M-2-chunking...', Resource id #320)\\n#3 \\\/home\\\/marginal\\\/public_html\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/CorePlugin.php(523): Sabre\\\\DAV\\\\Server->createFile('Test\\\/100M-2-chu...', Resource id #320, NULL)\\n#4 [internal function]: Sabre\\\\DAV\\\\CorePlugin->httpPut(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#5 \\\/home\\\/marginal\\\/public_html\\\/3rdparty\\\/sabre\\\/event\\\/lib\\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\\n#6 \\\/home\\\/marginal\\\/public_html\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(459): Sabre\\\\Event\\\\EventEmitter->emit('method:PUT', Array)\\n#7 \\\/home\\\/marginal\\\/public_html\\\/3rdparty\\\/sabre\\\/dav\\\/lib\\\/DAV\\\/Server.php(248): Sabre\\\\DAV\\\\Server->invokeMethod(Object(Sabre\\\\HTTP\\\\Request), Object(Sabre\\\\HTTP\\\\Response))\\n#8 \\\/home\\\/marginal\\\/public_html\\\/apps\\\/dav\\\/appinfo\\\/v1\\\/webdav.php(55): Sabre\\\\DAV\\\\Server->exec()\\n#9 \\\/home\\\/marginal\\\/public_html\\\/remote.php(138): require_once('\\\/home\\\/marginal\\\/...')\\n#10 {main}\",\"File\":\"\\\/home\\\/marginal\\\/public_html\\\/apps\\\/dav\\\/lib\\\/connector\\\/sabre\\\/file.php\",\"Line\":406,\"User\":\"xxx\"}","level":4,"time":"2016-05-16T22:32:54+00:00","method":"PUT","url":"\/remote.php\/webdav\/Test\/100M-2-chunking-1949736465-20-8","user":"xxx"}
Browser log
n/a
Activity
PVince81 commentedon May 17, 2016
I'd also suspect that.
Are you able to do a
ls -lof the chunk file before it disappears ?The way how cleanup works is that it sets the mtime of the chunk 24 hours in the future.
Then cleanup job is triggered at login time (login hook) and would discard all chunks which mtime is < now. Maybe the timestamp / timezone of the server is causing the mtime to be wrong ?
Marginal commentedon May 17, 2016
Yes - the offending chunk files are definitely created on the filesystem, and are visible to a sftp client (I'm running on shared hosting).
I'm looking into this now. While the chunk file is being written to the mtime ~= now. The mtime is only set 24hrs into the future after the file handle has been closed, in OC\Cache\File::set.
PVince81 commentedon May 17, 2016
Hmmmm, indeed. But then there shouldn't be a huge time window during the time the file is written and the
touchoperation is done.Unless
file_put_contentsis slow and already creates the file entry while it's writing it ?Chunks are usually 20 mb big, and if the transfer is slow...
Also the code uses a
.partfile while it's being written. But the gc code doesn't care about extension. This is correct because we might want to clear stray part chunks too.Were you able to observe the time between the moment where the part file is being written, does it exist ?
You might be onto something, keep posting your findings 😄
Will do some local testing with a debugger, this looks fishy.
PVince81 commentedon May 17, 2016
I did some debugging and found out that this
file_put_contentsfrom chunking is actually callingstreamCopyin a loop, because the chunk contents is a file handle, not data.When checking the timestamp of the file on-disk I noticed that for every
fwritethe mtime of the file was changed. So it's a game of cat and mouse until the GC comes to eat the file if its mtime happens to be older than now.CC @RealRancor @guruz
PVince81 commentedon May 17, 2016
So basically there's a loop that copies the bytes 8k by 8k, and for every
fwritethe timestamp gets adjusted. If one of them takes longer and at the same time a login hook is triggered, it will kill the chunk too early.PVince81 commentedon May 17, 2016
@Marginal great debugging, thank you!
PVince81 commentedon May 17, 2016
A possible fix would be to not use
touchbut do actual time calculation in thegcmethod.Basically, instead of setting the chunk's mtime to the future we leave it be and do the
gcon files wheremtime < now - 24hoursMarginal commentedon May 17, 2016
Yep - I added some logging to OC\Cache\File::gc and I can see this happening:
I guess the chunk file should be locked while being written?
PVince81 commentedon May 17, 2016
I just realized that the
setfunction is expecting attlhere: https://github.com/owncloud/core/blob/v9.0.2/lib/private/cache/file.php#L100This must be why it was implemented this way. So the approach of moving the ttl away won't work.
However I'm not aware of any code path that uses that
$ttlargument.@Marginal let's examine your idea about locking.
It looks like the code that calls
file_put_contentsalready acquires locks.But the
gcone doesn't, so let's see if we can add lock acquiring there as well.PVince81 commentedon May 17, 2016
Hmmm, I went through with a debugger and found out that both
file_put_contentsfromOC_FileChunkingand alsounlinkfromgcwill acquire locks using the locking provider.However from what I remember the locking provider was limited to work only on the "files/" entries, not the "cache/" entries. If we make it work on the latter as well, it should prevent such situations.
Marginal commentedon May 17, 2016
I can see that OC\Files\View::file_put_contents is creating locks, but I'm not seeing any "Could not cleanup locked chunk" debug messages from OC\Cache\File::gc so they're not being applied.
22 remaining items
PVince81 commentedon May 18, 2016
@Marginal thanks for testing!
master PR is here: #24691 (for 9.1)
I'll list the backport PRs in that one.
guruz commentedon May 18, 2016
Awersome to see this fixed!
PVince81 commentedon May 18, 2016
Yep. The reason why we didn't find it earlier is because it's hidden behind a
$storage->file_put_contents()call which, at first appearance, should be atomic. However, due to the many layers of OC, that call is transformed to a loop that copies blocks which isn't atomic.PVince81 commentedon May 18, 2016
I'm going to link all other related tickets to this one for the solution.
For those of you arriving here from other tickets, please try this PR #24691 or one of the related backports #24691 (comment). Alternatively you can just wait for the next maintenance releases 😄
PVince81 commentedon May 18, 2016
@RealRancor if you see people on the forums with the error "Expected filesize X got 0", you might want to direct them to this solution. Thanks 😄
enoch85 commentedon May 18, 2016
Finally! Thanks @Marginal and @PVince81 🎆 👍
lock commentedon Aug 4, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.