Hi Stefan,

first off, CouchDB 1.6.1 is no longer supported by this project AND it
has a long list of CVEs[1] against it. You REALLY should be operating
on a newer version.

Secondly, just to understand your motivation: you think closing and
opening the fds after the file:rename/2 call will make things work
for your SMB operation?

If yes, the only think I could spot that is substantially different, is
that the NewFd position is advanced implicitly by the underlying
file:pread/3 in [2] and your SwappedFd doesn’t get the same treatment,
but I don’t know why that should block the gen server call, as that only
does some refcounting updates[3]. While this includes stopping the
gen_server[4], I don’t see how the Pid this operates on should be any
different under your patch.

So:

1. How did you verify that the gen_server:call/3 call never returns?
2. Do you get any pertinent lines (especially crashes) in your couch.log?
3. Can you share your environment where you get to compile 1.6.1
   successfully, so we can try and reproduce this?
4. Could it be that your SMB implementation doesn’t allow for opening and
   closing files in this quick succession (with our without a rename in
   the mix)?


[1]: https://docs.couchdb.org/en/stable/cve/index.html
[2]: 
https://github.com/apache/couchdb/blob/1.6.x/src/couchdb/couch_db_updater.erl#L179
[3]: 
https://github.com/apache/couchdb/blob/1.6.x/src/couchdb/couch_db.erl#L1122-L1130
[4]: 
https://github.com/apache/couchdb/blob/1.6.x/src/couchdb/couch_ref_counter.erl#L84


Best
Jan
— 
Professional Support for Apache CouchDB:
https://neighbourhood.ie/couchdb-support/

24/7 Observation for your CouchDB Instances:
https://opservatory.app


> On 28. Feb 2023, at 10:19, Stefan Kral <stefan.k...@emlix.com> wrote:
> 
> Hi,
> 
> I'm experimenting with a CouchDB setup on a SMB mount point. I know this
> is not supported, but I ran into a (maybe simple) problem I don't
> understand. Maybe someone of you can give a hint easily (that would be
> amazing).
> 
> Given the following patch (I need to close/reopen the file descriptors
> after renaming) for the function
> https://github.com/apache/couchdb/blob/1.6.x/src/couchdb/couch_db_updater.erl#L176
> 
>>  1 --- a/src/couchdb/couch_db_updater.erl
>>  2 +++ b/src/couchdb/couch_db_updater.erl
>>  3 @@ -202,8 +202,18 @@ handle_call({compact_done, CompactFilepath}, _From, 
>> #db{filepath=Path}=Db) ->
>>  4          RootDir = couch_config:get("couchdb", "database_dir", "."),
>>  5          couch_file:delete(RootDir, Filepath),
>>  6          ok = file:rename(CompactFilepath, Filepath),
>>  7 +
>>  8 +        ok = couch_file:close(NewDb#db.updater_fd),
>>  9 +        ok = couch_file:close(NewDb#db.fd),
>> 10 +        {ok, SwappedFd} = couch_file:open(Filepath),
>> 11 +        SwappedReaderFd = open_reader_fd(Filepath, Db#db.options),
>> 12 +        SwappedDb = NewDb2#db{
>> 13 +            fd = SwappedReaderFd,
>> 14 +            updater_fd = SwappedFd
>> 15 +        },
>> 16 +        unlink(SwappedFd),
>> 17          close_db(Db),
>> 18 -        NewDb3 = refresh_validate_doc_funs(NewDb2),
>> 19 +        NewDb3 = refresh_validate_doc_funs(SwappedDb),
>> 20          ok = gen_server:call(Db#db.main_pid, {db_updated, NewDb3}, 
>> infinity),
>> 21          couch_db_update_notifier:notify({compacted, NewDb3#db.name}),
>> 22          ?LOG_INFO("Compaction for db \"~s\" completed.", [Db#db.name]),
> 
> then the gen_server:call() of line 20 never returns.
> 
> Is there a major issue with this approach or just a minor mistake in my
> implementation?
> 
> 
> Thank you for having a look,
> Stefan

Reply via email to