treasure-data / serverengine

A framework to implement robust multiprocess servers like Unicorn
Apache License 2.0
759 stars 86 forks source link

SocketManager: Enable `open(nil)` to select path automatically #143

Closed daipom closed 1 year ago

daipom commented 1 year ago

I already created

but we need a more fundamental solution as discussed in #140.

This PR enables ServerEngine::SocketManager::Server.open(nil) to select path automatically.

Especially on Windows, it is hard to search an available port for path, so we should use this feature. (The current generate_path logic sometimes chooses an unavailable port. For example, it does not consider the excluded port range.)

This fix keeps backward compatibility.

daipom commented 1 year ago

Though quite late now, I'm starting to think this may be better...

https://github.com/treasure-data/serverengine/blob/6c23c4ad2dec08635b4e77609088ff069c604959/lib/serverengine/socket_manager.rb#L91-L93

def self.open(path = nil)
  return new(path) unless path.nil?
  if ServerEngine.windows?
    new(0)
  else
    new(self.generate_path)
  end
end
daipom commented 1 year ago

Though quite late now, I'm starting to think this may be better...

https://github.com/treasure-data/serverengine/blob/6c23c4ad2dec08635b4e77609088ff069c604959/lib/serverengine/socket_manager.rb#L91-L93

def self.open(path = nil)
  return new(path) unless path.nil?
  if ServerEngine.windows?
    new(0)
  else
    new(self.generate_path)
  end
end

What do you think? If so, I will fix.

ashie commented 1 year ago

Thanks!

daipom commented 1 year ago

Thanks for your review!