On Wed, 6 Sep 2017 at 5:40 am, Ken Payson <kpay...@google.com> wrote:

> On Tue, Sep 5, 2017 at 6:07 AM, Amit Saha <amitsaha...@gmail.com> wrote:
>
>>
>>
>> On Tue, Sep 5, 2017 at 9:02 AM Amit Saha <amitsaha...@gmail.com> wrote:
>>
>>> On Tue, 5 Sep 2017 at 6:44 am, Ken Payson <kpay...@google.com> wrote:
>>>
>>>> gRPC Python sets the SO_REUSEADDR option on server sockets, which
>>>> allows multiple servers to bind to the same port.
>>>>
>>>
>>> Thanks. Is there any reason why this is set to be the default behavior?
>>>
>>
>> Searching around, I can see that this *may* be desired behavior and hence
>> gRPC has made a pragmatic choice. However, it seems to be most useful in a
>> scenario where an existing socket is in the TIME_WAIT state and we want a
>> new server process to bind to the same addr/port. However, two questions:
>>
>>
>
>> 1. This is not the case here - both of my servers are in LISTEN
>>
> I think you are referring to the SO_REUSEPORT option.  The SO_REUSEADDR is
> different, and is intended for having multiple processes bind to the same
> port.  One advantage of this is that you can scale by having multiple
> processes serving requests.
>

Sorry, but whatever I read seems to suggest the behavior you mention for
SO_REUSEPORT and not SO_REUSEADDR. I will definitely look more, but if you
have a handy reference you can share, that will be great.



>> 2. Next, considering (1), does it not introduce a race condition when we
>> have more than one process listening on the same socket? (let's say for
>> whatever reason, a server process is already running and we have started
>> another unaware, since we don't get an error).
>>
>
> If you want to avoid this behavior, you can disable it by passing a server
> option:
>
> grpc.server(thread_pool, options=(('grpc.so_reuseport', 0),))
>
>
Thanks.



>> Will appreciate any insights/pointers.
>>
>> Thanks,
>> Amit.
>>
>>
>>
>>
>>>
>>>
>>>
>>>> On Mon, Sep 4, 2017 at 5:58 AM, Amit Saha <amitsaha...@gmail.com>
>>>> wrote:
>>>>
>>>>> Hey all,
>>>>>
>>>>> This is the relevant part of my server:
>>>>>
>>>>> def serve():
>>>>>   server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
>>>>>   users_service.add_UsersServicer_to_server(UsersService(), server)
>>>>>   res = server.add_insecure_port('127.0.0.1:50051')
>>>>>   server.start()
>>>>>   try:
>>>>>     while True:
>>>>>       time.sleep(_ONE_DAY_IN_SECONDS)
>>>>>   except KeyboardInterrupt:
>>>>>     server.stop(0)
>>>>>
>>>>>
>>>>> On OS X, by mistake i started the server twice in different terminal
>>>>> sessions and I expected it to fail the second time (address already bound,
>>>>> etc). However, it didn't error out and this is what I see via lsof:
>>>>>
>>>>> $ sudo lsof -iTCP:50051
>>>>>
>>>>> COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
>>>>> Python  12120 amit    4u  IPv6 0xffbffb1742aa0f0f      0t0  TCP
>>>>> localhost:50051 (LISTEN)
>>>>> Python  12157 amit    4u  IPv6 0xffbffb1742aa144f      0t0  TCP
>>>>> localhost:50051 (LISTEN)
>>>>>
>>>>> Curiously enough, they both have the same FD.
>>>>>
>>>>> (I verified it with a Flask application to see if it was something
>>>>> Python specific, and i do see the expected error message when I try to
>>>>> start a second instance of the same)
>>>>>
>>>>> Thanks for any hints in advance.
>>>>>
>>>>> Best Wishes,
>>>>> Amit.
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "grpc.io" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to grpc-io+unsubscr...@googlegroups.com.
>>>>
>>>>
>>>>> To post to this group, send email to grpc-io@googlegroups.com.
>>>>> Visit this group at https://groups.google.com/group/grpc-io.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/grpc-io/7bef9f00-c9fa-4cdc-91c7-c3555c177c9a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/grpc-io/7bef9f00-c9fa-4cdc-91c7-c3555c177c9a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CANODV3%3DGx7nSS5N%3DhwtAULXMimWs81vift5QoFC9aH0YPzjfSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to