Using socket module in production?

Raimo Niskanen raimo+erlang-questions@REDACTED
Mon Jun 22 09:52:38 CEST 2020


On Fri, Jun 12, 2020 at 04:31:50PM +0000, Vans S wrote:
>  We notice often using gen_tcp with sockets backend we get this warning printed:
> 
> 3:24:4.923 <0.1018.0> [module: :gen_tcp_socket, socket: {:"$socket", #Reference<0.504347063.3068526593.55942>}, unknown_event: {:info, {:"$socket", {:"$socket", #Reference<0.504347063.3068526593.55942>}, :select, #Reference<0.504347063.3083599875.167918>}}, state: :connected]
> 

Thanks for the report - I will keep an eye open for such stray messages...

Are you using active mode, toggling active on/off, mixing explicit receive
with active receive or anything like that?

Are you using a packet mode, if so which?

/ Raimo


> Ignore the log format this is our custom format.
> 
> Seems to be some kinda race condition in the implementation.
>     On Friday, June 12, 2020, 09:30:07 a.m. EDT, pablo platt <pablo.platt@REDACTED> wrote:  
>  
>  Hi Raimo,
> I don't mind small changes in the API if changes will be indicated in the release notes.But I worry about other breaking changes or hidden bugs.If anyone from the community is already using it in production it will be reassuring.
> Thank you.
> 
> On Fri, Jun 12, 2020 at 4:00 PM Raimo Niskanen <raimo+erlang-questions@REDACTED> wrote:
> 
> Hi Pablo!
> 
> We will still make backwards incompatible changes.  But we do not know of
> any stability issues, and welcome all that stress test the code.
> 
> So your code might stop working work in a future 23.X release.
> 
> / Raimo
> 
> 
> On Fri, Jun 12, 2020 at 01:48:32PM +0300, pablo platt wrote:
> > Hi,
> > 
> > Is it safe to use the NIF socket module for UDP in production in OTP 23?
> > It's working in my tests but I'm not sure if it's considered unstable or if
> > I'm missing configuration or error handling.
> > 
> > This is how I'm using it:
> > 
> > open() ->
> >   {ok, Socket} = socket:open(inet, dgram, udp),
> >   {ok, Port} = socket:bind(Socket, any),
> >   {Socket, Port}.
> > 
> > active_once(Socket) ->
> >     case socket:recvfrom(Socket, 0, [], nowait) of
> >         {ok, {#{port := Port, addr := Addr}, Data}} ->
> >             {udp, Addr, Port, Data};
> >         {select, {select_info, _SelectTag, SelectRef}} ->
> >             SelectRef;
> >         {error, Reason} ->
> >             exit(Reason),
> >             error
> >     end.
> > 
> > send(Socket, Addr, Port, Data) ->
> >     Dest = #{family => inet,
> >              port => Port,
> >              addr => Addr},
> >     case socket:sendto(Socket, Data, Dest, [], nowait) of
> >         ok -> ok;
> >         {select, {select_info, _SelectTag, _SelectRef}} ->
> >             % need to wait for {'$socket', Socket, select, SelectRef}  and
> > resend Data?
> >             ok
> >     end.
> > 
> > close(Socket) ->
> >     socket:close(Socket).
> > 
> > % listen for select ref
> > handle_info({'$socket', Socket, select, SelectRef}, _State) ->
> >     case socket:recvfrom(Socket, 0, [], nowait) of
> >         {ok, {#{port := Port, addr := Addr}, Data}} ->
> >             % handle Data
> >             ok;
> >         {select, {select_info, _SelectTag, SelectRef}} ->
> >            SelectRef;
> >      {error, Reason} ->
> >          exit(Reason),
> >          error
> >     end,
> >     {noreply, State}.
> 
> -- 
> 
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
> 
>   

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list