boostorg / interprocess

Boost.org interprocess module
http://boost.org/libs/interprocess
138 stars 118 forks source link

infinite loop in managed_open_or_create_impl.hpp if filesize is 0 #130

Closed cmorty closed 3 years ago

cmorty commented 4 years ago

Calling managed_mapped_file(bip::open_only,filename) on a file with size 0 results in a in infinite loop.

            offset_t filesize = 0;
            spin_wait swait;
            while(filesize == 0){
               if(!get_file_size(file_handle_from_mapping_handle(dev.get_mapping_handle()), filesize)){
                  error_info err = system_error_code();
                  throw interprocess_exception(err);
               }
               swait.yield();
            }
igaztanaga commented 3 years ago

A correctly created managed file can't have zero size. Code is waiting the create process to initialize the managed file (in case of error, file will be truncated to size 1). Which is your use case?

igaztanaga commented 3 years ago

Thanks for the report. The implementation will add deadlock detection code with configurable macros BOOST_INTERPROCESS_MANAGED_OPEN_OR_CREATE_INITIALIZE_MAX_TRIES/BOOST_INTERPROCESS_MANAGED_OPEN_OR_CREATE_INITIALIZE_TIMEOUT_SEC to handle those situations, as there is no reliable way to detect the other process creating the resource is dead or not.