services_remove does not unload modules
MaartenFaddegon opened this issue · comments
Maarten Faddegon commented
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:
- 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
- Compile
erlc -pz /usr/local/lib/cloudi-1.7.0/lib/cloudi_core-1.7.0/ebin \
hello_world.erl
- Add current directory to code path
curl -X POST -d '"'`pwd`'"' \
http://localhost:6464/cloudi/api/rpc/code_path_add.erl
- Create configuration file
cat << EOF > hello_world.conf
[[{prefix, "/quickstart/erlang/"},
{module, hello_world}]]
EOF
- Add the hello_world service
curl -X POST -d @hello_world.conf \
http://localhost:6464/cloudi/api/rpc/services_add.erl
- The service now returns "Hello World!" as expected
curl http://localhost:6464/quickstart/erlang/hello_world
- 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
- Change the code
sed 's/Hello World/Hello Again/' -i hello_world.erl
- Recompile
erlc -pz /usr/local/lib/cloudi-1.7.0/lib/cloudi_core-1.7.0/ebin \
hello_world.erl
- Re-add the hello_world service
curl -X POST -d @hello_world.conf \
http://localhost:6464/cloudi/api/rpc/services_add.erl
- The service unexpectedly returns "Hello World!" instead of "Hello Again!"
curl http://localhost:6464/quickstart/erlang/hello_world
Michael Truog commented
@MaartenFaddegon Thank you for reporting this bug. This is now fixed and will be released in version 1.7.1 later this week.