obi458 commented on issue #1182: fixed race is_idle URL: https://github.com/apache/couchdb/pull/1182#issuecomment-368962363 One solution may be: If we are going to close the Db(couch_file) we try: ``` is_idle() -> .... andalso ets:insert_new(couch_dbs,self()). ``` Further if we are going to monitor the Fd: ``` incref(#db{fd = Fd} = Db) -> incref(Db,ets:insert_new(couch_dbs,Fd)). incref(#db{fd = Fd} = Db, true = _Ready) -> % first monitor Ref = erlang:monitor(process, Fd), % than release the lock ets:delete(couch_dbs,Fd), {ok, Db#db{fd_monitor = Ref}}; % we are not able to write the lock, % either the file will be closed or another process want to monitor % we will try it again incref(#db{fd = _Fd} = Db, false = _Ready) -> retry. ``` and ``` ... case couch_db:incref(Db0) of retry -> open(DbName, Options0); {ok, Db1} -> couch_db:set_user_ctx(Db1, Ctx) end; ... ... case couch_db:incref(Db0) of retry -> create(DbName, Options0); {ok, Db1} -> couch_db:set_user_ctx(Db1, Ctx) end; ... ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
