CloudI / CloudI

A Cloud at the lowest level!

Home Page:https://cloudi.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

services_remove does not unload modules

MaartenFaddegon opened this issue · comments

After removing an internal service with services_remove and re-adding a newer version of the internal_service cloudi still serves the old-version of the service.

To reproduce:

  1. The old version of the code
cat << EOF > hello_world.erl
-module(hello_world).
-behaviour(cloudi_service).

%% cloudi_service callbacks
-export([cloudi_service_init/4,
         cloudi_service_handle_request/11,
         cloudi_service_handle_info/3,
         cloudi_service_terminate/3]).

-include_lib("cloudi_core/include/cloudi_logger.hrl").

-record(state,
    {
    }).

cloudi_service_init(_Args, _Prefix, _Timeout, Dispatcher) ->
    cloudi_service:subscribe(Dispatcher, "hello_world/get"),
    {ok, #state{}}.

cloudi_service_handle_request(_Type, _Name, _Pattern,
                              _RequestInfo, _Request,
                              _Timeout, _Priority,
                              _TransId, _Pid,
                              #state{} = State, _Dispatcher) ->
    {reply, <<"Hello World!">>, State}.

cloudi_service_handle_info(Request, State, _Dispatcher) ->
    ?LOG_WARN("Unknown info \"~p\"", [Request]),
    {noreply, State}.

cloudi_service_terminate(_Reason, _Timeout, #state{}) ->
    ok.
EOF 
  1. Compile
erlc -pz /usr/local/lib/cloudi-1.7.0/lib/cloudi_core-1.7.0/ebin \
    hello_world.erl
  1. Add current directory to code path
curl -X POST -d '"'`pwd`'"' \
    http://localhost:6464/cloudi/api/rpc/code_path_add.erl
  1. Create configuration file
cat << EOF > hello_world.conf
[[{prefix, "/quickstart/erlang/"},
  {module, hello_world}]]
EOF
  1. Add the hello_world service
curl -X POST -d @hello_world.conf \
    http://localhost:6464/cloudi/api/rpc/services_add.erl
  1. The service now returns "Hello World!" as expected

curl http://localhost:6464/quickstart/erlang/hello_world

  1. Remove the service using the UUID returned in step 5 (returns ok)

curl -X POST -d '["UUID"]' http://localhost:6464/cloudi/api/rpc/services_remove.erl

  1. Change the code

sed 's/Hello World/Hello Again/' -i hello_world.erl

  1. Recompile
erlc -pz /usr/local/lib/cloudi-1.7.0/lib/cloudi_core-1.7.0/ebin \
    hello_world.erl
  1. Re-add the hello_world service
curl -X POST -d @hello_world.conf \
    http://localhost:6464/cloudi/api/rpc/services_add.erl
  1. The service unexpectedly returns "Hello World!" instead of "Hello Again!"

curl http://localhost:6464/quickstart/erlang/hello_world

@MaartenFaddegon Thank you for reporting this bug. This is now fixed and will be released in version 1.7.1 later this week.