Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

sys protocol in websocket handler #454

Open
maxlapshin opened this Issue · 11 comments

3 participants

@maxlapshin

I've got bad situation with leaking websocket handler:

(flussonic@127.0.0.1)5> sys:get_status(pid(0,30511,29)).
22:38:01.936 <0.30511.29> api_handler:272 api_websocket msg: {system,{<0.30811.81>,#Ref<0.0.163.218563>},get_status}
** exception exit: {timeout,{sys,get_status,[<0.30511.29>]}}
in function sys:send_system_msg/2 (sys.erl, line 231)
(flussonic@127.0.0.1)6>
(flussonic@127.0.0.1)6> process_info(pid(0,30511,29)).

{current_function,{cowboy_websocket,handler_loop,4}},
{initial_call,{cowboy_protocol,init,4}},
{status,waiting},
{message_queue_len,0},
{messages,[]},
{links,[<0.188.0>,<0.196.0>,#Port<0.669854>]},
{dictionary,[]},
{trap_exit,false},
{error_handler,error_handler},
{priority,normal},
{group_leader,<0.89.0>},
{total_heap_size,2514875},
{heap_size,832040},
{stack_size,14},
{reductions,272853732},
{garbage_collection,[{min_bin_vheap_size,46368},
{min_heap_size,233},
{fullsweep_after,65535},
{minor_gcs,6}]},
{suspending,[]}
7> process_info(pid(0,30511,29),memory).
{memory,20119888}

20 megabytes in small websocket =)

And I cannot inspect it with sys protocol.

If you are going to merge pull request, I can add support for sys protocol to websockets.

@essen
Owner

What I ultimately want is to have them be special processes, but not just websockets, all HTTP processes.

@maxlapshin
@essen
Owner

Special processes mean started with proc_lib and handling sys messages, they do neither of these things at this time.

If they are made special processes, that means we need to handle sys messages everywhere, not just in the websocket code. You could do it just in the websocket code to debug your issue but that would not be enough for a merge (though a PR is still welcome).

@maxlapshin
@essen
Owner

Yeah it would be a hackish way to make half of sys work, but then the other half would break horribly because it assumes the process was started using proc_lib. If you receive a system message saying the process should be suspended then your process will simply crash. We can't have that. Gotta go all the way.

@maxlapshin
@essen
Owner

No problem? You just have to handle system messages everywhere and not just with websockets like I said.

@asabil

You might want to take a look at gen_process: https://github.com/asabil/gen_process

@essen
Owner

It's doing much more than we want. We just need the proc_lib:start and handling system messages. The "hard" part is to find the right way to do it while still keeping the code as efficient as it is now.

@asabil

Yes probably, which features do you see as being unnecessary in your case?

@essen
Owner

Pretty much all of it. It doesn't work quite the same way here, the process goes through many different modules, a good number of them needing to receive messages and handle system events. There's no need for calling the process either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.