Skip to content

Instantly share code, notes, and snippets.

@rhumbertgz
Last active August 29, 2015 14:26
Show Gist options
  • Save rhumbertgz/4881014e921572e7bca4 to your computer and use it in GitHub Desktop.
Save rhumbertgz/4881014e921572e7bca4 to your computer and use it in GitHub Desktop.
Hello, I have been working in a extension to riak_pb, but every time that I try to use my new message in my extension of riak_erlang_client I obtain this message "Socket error while sending riakc request: einval. Bad value on output port 'tcp_inet'". These files represent a dummy example that replicate my error. Any suggestion?
-module(demo_api_pb_service).
-behaviour(riak_api_pb_service).
-export([init/0,
decode/2,
encode/1,
process/2,
process_stream/3]).
-include_lib("riak_pb/include/demo_pb.hrl").
init() ->
undefined.
%% @doc decode/2 callback. Decodes an incoming message.
decode(Code, Bin) when Code == 605 ->
Msg = riak_pb_codec:decode(Code, Bin),
case Msg of
#greeting{msg=M, from=F} ->
Hook = {M,F},
{ok, Msg, {"demo.greet", Hook}}
end.
%% @doc encode/1 callback. Encodes an outgoing response message.
encode(Message) ->
{ok, riak_pb_codec:encode(Message)}.
%% Get bucket properties
process(#greeting{msg = M}, State) ->
{error, {format, "Message: ~p", [M]}, State}.
process_stream(_, _, State) ->
{ignore, State}.
-module(riak_api_app).
-behaviour(application).
-export([start/2,
stop/1]).
-define(SERVICES, [{riak_api_basic_pb_service, 1, 2},
{riak_api_basic_pb_service, 7, 8},
%% Note: Riak core cannot register this itself,
%% because it is started before riak_api.
{riak_core_pb_bucket, 19, 22},
{riak_core_pb_bucket, 29, 30},
{riak_core_pb_bucket_type, 31, 32},
{demo_api_pb_service, 600, 610}
]).
%% @doc The application:start callback.
-spec start(Type, StartArgs)
-> {ok, Pid} | {ok, Pid, State} | {error, Reason} when
Type :: normal
| {takeover, Node :: node()}
| {failover, Node :: node()},
Pid :: pid(),
State :: term(),
StartArgs :: term(),
Reason :: term().
start(_Type, _StartArgs) ->
riak_core_util:start_app_deps(riak_api),
case riak_api_sup:start_link() of
{ok, Pid} ->
riak_core:register(riak_api, [{stat_mod, riak_api_stat}]),
ok = riak_api_pb_service:register(?SERVICES),
{ok, Pid};
{error, Reason} ->
{error, Reason}
end.
%% @doc The application:stop callback.
-spec stop(State::term()) -> ok.
stop(_State) ->
ok = riak_api_pb_service:deregister(?SERVICES),
ok.
-module(riakc_pb_socket).
-include_lib("kernel/include/inet.hrl").
-include_lib("riak_pb/include/riak_pb.hrl").
-include_lib("riak_pb/include/riak_kv_pb.hrl").
-include_lib("riak_pb/include/riak_pb_kv_codec.hrl").
-include_lib("riak_pb/include/riak_search_pb.hrl").
-include_lib("riak_pb/include/riak_yokozuna_pb.hrl").
-include_lib("riak_pb/include/riak_dt_pb.hrl").
-include_lib("riak_pb/include/demo_pb.hrl").
-include("riakc.hrl").
-behaviour(gen_server).
...
%% Reactive extension
-export([greeting/3]).
...
greeting(Pid, Msg, From)->
Req = #greeting{msg= Msg, from=From},
call_infinity(Pid, {req, Req, infinity}).
...
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 3 in line 1.
...
80,DtFetchReq,riak_dt
81,DtFetchResp,riak_dt
82,DtUpdateReq,riak_dt
83,DtUpdateResp,riak_dt
253,RpbAuthReq,riak
254,RpbAuthResp,riak
...
605,Greeting,demo
...
// java package specifiers
option java_package = "com.basho.riak.protobuf";
option java_outer_classname = "DemotPB";
message Greeting {
required bytes msg = 1;
required bytes from = 2;
}
1> {ok, Pid} = riakc_pb_socket:start("127.0.0.1", 8087).
{ok,<0.34.0>}
2> riakc_pb_socket:ping(Pid).
pong
3> riakc_pb_socket:greeting(Pid, <<"Hello world!">>, <<"humbert">>).
{error,disconnected}
=ERROR REPORT==== 4-Aug-2015::18:00:54 ===
Socket error while sending riakc request: einval.
=ERROR REPORT==== 4-Aug-2015::18:00:54 ===
Bad value on output port 'tcp_inet'
@rhumbertgz
Copy link
Author

Hello, I solved the problem with the help of @sargun in the channel of riak at webchat.freenode.net.

The error was in the code of my message (625). This number (605 >= 255) breaks the format of 8-bit message code to identify the Protocol Buffers message.

I changed the code of my message and it works!

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment