clemensm

clemensm

Phoenix Channel sometimes stop working because :handle_info function is no longer exported

Hi there

I’ve run into a really strange problem in one of my apps recently, which I sadly cannot reproduce reliably but do see from time to time in :dev and :prod environments.

So I’ve got an app where users can create “cards” with some content on them, and we’ve got a list of all cards the user owns where he can search for his cards. The searches can be quite complicated, so what we’ve implemented is that the search request is send to the server which performs the search and then sends back the result in form of rendered html as a string. The result itself is sent using a channel called “search:unique_identifier_for_each_search_instance”, to which the client subscribes on loading of the app. The html is then received on the client and the current table with the results is replaced with the received new result.

This all is a bit more complicated then necessary, but a lot of this functionality has grown over time, so for now it is what it is :slight_smile:

Now the socket that the channel belongs to hosts multiple channels, e.g. another one is “alert:user_id” in order to send the user information if something goes wrong, of ir new cards are received from other users, just in case this might be important.

So finally the problem: Usually all this works fine, but from time to time what can happen is, that if the user navigates back in the browser (the frontend is an SPA, so the socket is not remounted), suddenly the search results are no longer sent to the client. Instead I get an error like this:

[warning] Phoenix.Channel.Server #PID<0.1296.0> received unexpected message in handle_info/2: 
{:new_result,   lots_of_html_here_that_is_truncated ......

So looking into the code of Phoenix.Channel.Server I found the place that triggers the message, and this only happens if function_exported?(MyApp.Channel.Search, :handle_info, 2) returns false. However the MyApp.Channel.Search module does actually export that function.

Next luck would have it that I triggered this error shortly afterwards while running the server using iex -S phx.server, and quickly checking the output of function_exported?(MyApp.Channel.Search, :handle_info, 2) in the console manually, the call does indeed return false. However after some digging around and trying it again, it now returns true, and the search also starts working as expected again. Also if I try function_exported?(MyApp.Channel.Search, :handle_info, 2) directly after starting the server, it also always returns true.

Does anyone have any idea how this can happen?

Thanks for your time already :smile:

First 3 of 3 Posts Switch mode

derek-zhou

derek-zhou

Are you running a release? With a release, the BEAM is in the embedded mode and barring from hot code reloading, the function_exported? shall always return the same value.

Iex is interactive mode, so the code may not be loaded, if no one has called any function in that module.

clemensm

clemensm OP

Hmm, I had the same thought yesterday. After checking the log files on the server I could actually not find the same error message, but I’m not sure if some sort of similiar problem still exists because in Phoenix.Channel.Server the logs are written using the Erlang :error_logger instead of the Elixir Logger. I’m just not sure if those logs are captured as well, but I’d guess so.

I’ll continue investigating on :prod, though I still don’t understand why in the :dev environment sometimes the function ceases to be exported…

clemensm

clemensm OP

Ok, I did some more investigating and it seems that @derek-zhou is correct in his answer above, thanks again. In :prod the error is not being logged, so I guess on :prod the issue is triggered by something else…

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement