Are there restrictions on making Plug.Conn calls across multiple processes?

This came up as an issue on Bandit recently, and is honestly something I’ve never thought about before. The situation is this:

  1. The underlying server (either Bandit or Cowboy) receives a connection from the client, creates a Plug.Conn struct and passes it to the configured Plug module in process A.

  2. Within Plug.call/2, details of the Plug.Conn structure get passed to another process, process B (the details of how this happens aren’t important here).

  3. Process B then attempts to call functions on Plug.Conn (say Plug.Conn.send_resp/3 for the sake of argument) using this Plug.Conn structure.

My question is: what should happen here?

It seems as if Cowboy allows this, and Bandit does as well for HTTP/1 connections. I have a check in Bandit’s HTTP/2 implementation that requires any calls to come from the process that Plug.call/2 was originally called from, but now that I think about it such a requirement is never explicitly called out as part of the Plug API contract. It strikes me that allowing this would open the door to any number of oddball concurrency issues however.

Do we collectively have a strong opinion on this one way or the other?

5 Likes

On maybe a tangent to this: What is the :owner pid in Plug.Conn meant to be used for? From what I could read in plug it seems that it’s only used to notify the owner process of what happened to the conn.

1 Like