rnewson commented on a change in pull request #3507:
URL: https://github.com/apache/couchdb/pull/3507#discussion_r613406164



##########
File path: src/couch/src/couch_file.erl
##########
@@ -711,10 +711,21 @@ read_raw_iolist_int(Fd, {Pos, _Size}, Len) -> % 0110 
UPGRADE CODE
     read_raw_iolist_int(Fd, Pos, Len);
 read_raw_iolist_int(#file{fd = Fd} = File, Pos, Len) ->
     {Pos, TotalBytes} = get_pread_locnum(File, Pos, Len),
-    {ok, <<RawBin:TotalBytes/binary>>} = file:pread(Fd, Pos, TotalBytes),
-    {remove_block_prefixes(Pos rem ?SIZE_BLOCK, RawBin), Pos + TotalBytes}.
-
+    case catch file:pread(Fd, Pos, TotalBytes) of
+        {ok, <<RawBin:TotalBytes/binary>>} ->
+            {remove_block_prefixes(Pos rem ?SIZE_BLOCK, RawBin), Pos + 
TotalBytes};
+        Else ->
+            % This clause matches when the file we are working with got 
truncated
+            % outside of CouchDB after we opened it. To find affected files, we
+            % need to log the file path.
+            %
+            % Technically, this should also go into 
read_multi_raw_iolists_int/2,
+            % but that doesn’t seem to be in use anywhere.
+            {_Fd, Filepath} = get(couch_file_fd),
+            throw({file_truncate_error, Else, Filepath})

Review comment:
       The original behaviour caused an `exit` which we're now softening to a 
`throw`. I think that's a mistake.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to