inaka / apns4erl Goto Github PK
View Code? Open in Web Editor NEWApple Push Notification Server for Erlang
Home Page: http://inaka.github.com/apns4erl
Apple Push Notification Server for Erlang
Home Page: http://inaka.github.com/apns4erl
When close a apns connection, the queue resource doesn't release,which leads to a lot of useless apns queue left in system that cannot be GC.
Add apns_queue:stop in apns_connection:terminate can fix it.
I got following in my logs. It is coming from apns4erl.
2015-04-29 00:01:59.992 [info] <0.3157.0> SSL: Socket error: etimedout
2015-04-29 00:01:59.992 [info] <0.395.0> APNS disconnected
Till this point I lost all my messages needed to be sent via apns.
After this, when I send another message:
I got following:
2015-04-29 00:03:03.134 [info] <0.395.0> Reconnecting to APNS...
Then I was able to send apns messages.
Would you know what could cause the disconnect?
Can I set any configuration to timeout faster to minimize loss of messages?
Should I disconnect and reconnect everytime I send a message?
I observe following code in test_suite:
apns:send_message(
?TEST_CONNECTION, ?DEVICE_TOKEN,
Now ++ " - Test Alert", random:uniform(10), "chime"),
receive
{'DOWN', Ref, _, _, _} = DownMsg ->
throw(DownMsg);
DownMsg ->
throw(DownMsg)
after 1000 ->
ok
end,
If I understand this correctly (new to Erlang) its looking for "DOWN" message which will come as part of connection monitoring if the connection goes down - Ref = erlang:monitor(process, Pid),
Please guide me to understand this better.
update deps thx
make tests doesn't even work :/
Hi,
I have successfully integrated apns4erl with our application and it's working fine, but some times below crash is happening and some APNs messages will not be sent because of the crash.
gen_server my_apns_connection terminated with reason: {error,closed}
09:37:53.977 [error] CRASH REPORT Process my_apns_connection with 1 neighbours exited with reason: {error,closed} in gen_server:terminate/7 line 826
09:37:53.978 [error] Supervisor apns_sup had child undefined started with apns_connection:start_link(my_apns_connection, {apns_connection,"gateway.push.apple.com",2195,undefined,"priv/certs/ios_privkey.pem",...}) at <0.6600.18> exit with reason {error,closed} in context child_terminated
I have investigate many in many ways, but couldn't find any clue, any Ideas?
Thanks,
udaya.
Hi!
I have two different client apps, one server.
In apns4erl, there is only one configure for cert_file.
Can i use one apns4erl to support two client apps?
We need to get this library into Erlang/OTP 18.x world.
The plan is to start using maps where we used records before, stop requiring headers, revisit the way we start/stop connections and how we properly display errors from APNS.
In the process, we should address as many open issues as possible and ensure 100% code coverage in tests.
In priv/cert.pem
.
The only tagged release, 1.0.0, doesn't support R16 and is missing a lot of new commits. Specifying HEAD as the dependency's version has caused me problems in the past, so I'd love to see a new release get tagged. Thanks!
I've a problem because I send messages in broadcast to several devices, apns return invalid_token for me every few seconds, I resend the msg for this invalid_token is ok, this means the returned invalid_token is ok. Why apns return invalid_token every few seconds?
Hi!
I use ./bin/xxx/console
, there is {<<147,20,71,130>>,invalid_token}
in the console.
How can i know which token is invalid?
the rebar.config mentions https://github.com/inaka/sync.git
but that repo does not exist anymore
Rebar config specify version 17 as maximum version number, is there known issues with Erlang 18 ?
I am new to erlang and ejabberd. I have gone through docs and tutorials on erlang and ejabberd.
I am still not sure how to integrate apns4erl with ejabberd. I need to be able to do the following:
Would you be able to give me starting pointers on to get apns4erl started with ejabberd??
Do I need to start apns4erl application from my custom module that I will hook with ejabberd. is that how it will work??
Thanks in advance!
Gaurav Jain
Jiffy 14.3 has fix this bug, but rebar.config use 13.3 now. Please upgrade it.
Its not a bug but I am looking for help. I tried SO
http://stackoverflow.com/questions/29906198/gen-server-terminated-with-reason-bad-return-value
Would you be able to help me?
Hello,
"case ssl:connect(
Connection#apns_connection.apple_host,
Connection#apns_connection.apple_port,
RealSslOpts,
Connection#apns_connection.timeout
) "
RealSslOpts is [{certfile,"/etc/certs/*.pem"},{mode,binary}],but I want to use "{cert, der_encoded()}" not "{certfile, path()}",how can I do? Thank you!
I get the following error when calling apns:connect(apns_push, ApnsConnection)
:
{error,{keyfile,{badmatch,[]}}}
where ApnsConnection is a apns_connection
-record. The key-file is set to undefined in ApnsConnection.
What could be the reason?
Indeed I've seen that there's another closed issue with the same name, but there's no any guide/tutorial that explains how to make this integration.
I don't know some things:
And some other things..
Someone can helps me?
Thanks!
Correct me if I am wrong, but if I wanted to create multiple connections to the APN services, I would simply call connect function with a different connection name atom. Would I not end up connecting to the feedback server in each gen_server worker which is probably redundant?
Thanks, O.
Hi,I've encountered a problem as the title describes
The Erlang version is R17.5,but the ssl version is 7.0(because ssl6.0 caused error})
I had to run the following command to generate a working certificate:
openssl pkcs12 -in production.p12 -out cert.pem -nodes
mv cert.pem priv/
I've a problem because I send messages in broadcast to several devices and when a token is invalid, all the messages sent between the wrong message and the error received by apns, are ignored.
I was reading this:
http://redth.info/the-problem-with-apples-push-notification-ser/
Do you have these errors? How do you solve them?
It was introduced in #72 for all, but it should only apply to sandbox (i.e. it must be a configuration option in the #apns_connection record).
After a couple of mails with @jamesgolick I understood that letting apns_connection
processes die normally when they're disconnected from Apple is not the best idea. This is the final mail
Since my applications usually send packs of notifications (i.e. the same notification to a bunch of users instead of just one notification to some user)… I run this code right before trying to send each pack:
ensure_started() -> try apns:connect(?APPLE_CONNECTION, fun handle_apns_error/2, fun handle_delete_subscription/1) of {ok, _} -> ok; {error, {already_started, _}} -> ok; {error, Reason} -> ?THROW("Couldn't start APNS4ERL: ~p. Apple Push Notifications will not work until the admin fixes this~n", [Reason]) catch _:Reason -> ?THROW("Couldn't start APNS4ERL: ~p. Apple Push Notifications will not work until the admin fixes this~n", [Reason]) end.After thinking about it for a while, I feel the right thing to do would be to keep apns_connection process running even when it was disconnected from Apple and then connect it again when it has a new notification to send… Most likely it would be a good idea to turn it into a gen_fsm… I'll probably implement that in the near future.
Thanks for the great library! We've been running it in production for three or four years with great success.
It looks like the change (bd9048e) to use queue:queue()
as a type rather than plain queue()
might have broken the build on releases older than R17:
ERLC apns.erl apns_queue.erl apns_sup.erl apns_connection.erl
src/apns_queue.erl:32: referring to built-in type queue as a remote type; please take out the module name
src/apns_queue.erl:111: referring to built-in type queue as a remote type; please take out the module name
make: *** [ebin/apns.app] Error 1
It looks like the OTP team knew this would be a backwards-incompatible change and introduced a compiler option to suppress the warning, which might be more appropriate than switching to the new type (at least until R18 is released): http://erlang.org/pipermail/erlang-questions/2014-March/078081.html
If support for older releases (R14, 15, and 16, as defined in the rebar.config
) is still desired, is it possible to use a preprocessor guard around the new types? We don't use types in our Erlang app, so I'm unsure here.
Here are the build results from three OTP versions: https://travis-ci.org/eleostech/apns4erl/builds/67406167
if the network is lost after apns is started, .eg. {error, nxdomain}
, the app crashes. What happens is when the feedback timeout occurs, a reconnect message is sent, which fails, crashing the gen_server
. The simple_one_for_one
strategy with transient
workers is quickly exhausted, crashing the supervisor and eventually the app.
Hello,I have a question:Why Feedback server disconnected as soon as I connected the feedback ok? And after I connected the feedback,the apns server will handle_info({ssl, SslSocket, Data}? give me the bad token? Thank you!!
hi,
After sending messages we get usual
Sending msg <<"½U÷N">> (expires on 1474400981)
but the message is not delivered to a device.
After some of those, connection to apple push server is closed.
We dont have feedback from apple, because connection to feedback server is also closed.
In both cases its sl_closed. What may be the reason of that?
It seems that it happens when we send some non-standard characters (emojis, ellipsis).
There are no crashes or side errors.
Any advice?
thanks
Hi,
I am experiencing an issue which I do not know how to resolve.
I am able to send notifications but when I delete the app, I do not receive feedback.
I started apns connection:
apns:connect(?APNS_CONNECTION, fun ?MODULE:handle_apns_error/2, fun ?MODULE:handle_apns_delete_subscription/1).
My handler is as follows:
handle_apns_delete_subscription(Token) ->
error_logger:warning_msg("Device with token ~p removed the app~n", [Token]),
I did not see the above output in my logs.
I logs I have
2015-04-03 05:38:58.863 [info] <0.388.0> Feedback server disconnected. Waiting 18000000 millis to connect again...
2015-04-03 10:38:59.191 [info] <0.388.0> Feedback server disconnected. Waiting 18000000 millis to connect again...
2015-04-03 15:38:59.301 [info] <0.388.0> Feedback server disconnected. Waiting 18000000 millis to connect again...
Would you be able to tell if I am missing something?
I am on Sandbox
Hey guys, I am trying to integrate apns4erl
with my Erlang application.
Is any reason to have rustyio/sync in rebar.config?, looks like it's for dev purposes only, isn't it?
In Apple APNS "The Feedback Service" doc section, this is mentioned:
Query the feedback service daily to get the list of device tokens. Use the timestamp to verify that the device tokens haven’t been reregistered since the feedback entry was generated. For each device that has not been reregistered, stop sending notifications.
There is a feedback connection. But how do I get data and process it? Is there an example?
Please provide pointers!
Currently apns4erl supports the "Enhanced Notification Format" (command=1), which is now legacy:
The latest notification format (command=2) is frame-based. Any plans to support this soon?
require_otp_vsn
on rebar.config
is set to {require_otp_vsn, "R1[456]"}
, which does not match with otp 17. It seems that {require_otp_vsn, "R1[456]|17"}
works.
Sending too many devices with wrong device ids causes closing socket by APNS server, which in turn crashes apns_connection
gen_server
.
The carsh is not a big deal, because apns_connection
is supervised, but send
function is using gen_server:cast
, so when the server crashes, all messages that were queued in process mailbox are gone and we don't know, what messages were there.
My solution to this problem would be to add gen_server:call
doing exactly the same thing - sending messages, but because it is synchronous, we might be sure that:
If you think, this is a good idea, I can make a pull request, but it would be great to fix #71 before that.
Otherwise, it is a little bit hard to test, if everything is working correctly.
If you can think of a better solution, I am open.
Hi!
I found the api apns:send_message
only one process to request apns service.
Why don't use a pool or multiple processes to send the message to apns?
Will it handle more requests per second if use multiple processes?
Hi,
When I do apns:connect I get an {error, closed} back in return. What is the recommended way of finding out why this happens? I do not see any logs anywhere and I see nothing on the console.
Also, I suspect this is due to some problems with my certificates - an area which I am in general a bit clueless about at the moment and I find it a bit complex. Is there some documentation on how the cert_file and key_file used in apns4erl relates to the Apple certificates (the developer certificate and the push notification certificates) or any good documentation on how to set it up? I have for instance both an aps.cer and aps_development.cer and I understand I should generate a .pem file to input to apns4erl. Which .p12 file should I combine with the .cer to generate the cert_file .pem and which files should I combine to generate the key_file .pem? In your example sys.config you leave the key_file as "undefined" but I really need to specify a keyfile don't I?
/Stefan
In the readme.md, following is mentioned:
NOTE 2: To generate the .pem file, from the .cer an .p12 files provided by Apple, you can use this "https://github.com/inaka/apns4erl/blob/master/inaka/apns4erl/blob/master/priv/test_certs"
Why is this step needed? Should not we get .pem files from Apple itself?
Could you please elaborate on this step?
What is purposes of apns_queue
module usage?
As far as I got we store push messages inside of queue just before send message itself, for sure, to handle case when connection to apple's server is unstable, or closed at the moment.
Also apns_queue
serves e to resend failed push messages.
But we do not remove successfully sent push message from that queue, and new messages just displace prev one.
Should I remove messages from queue by myself? Looks like no, cause there is no any interface funs to do this.
Please, provide simple tutorial for apns4erl
Hi! I have no problem using one certificates, just specifying it in sys.conf and everything works.
But I want to have different connections with different certificates, so I have to use this sample:
Connection = #apns_connection{cert_file=undefined,
cert=CertDER,
key={'RSAPrivateKey', KeyDER}},
apns:connect(Connection).
The problem is, that I got errors:
{badmatch,{error,{{badarg,[{ets,select_delete,[undefined,[{{{undefined,'_','_'},'_'},[],[true]}]],[]},{ets,match_delete,2,[{file,"ets.erl"},{line,700}]},{ssl_pkix_db,remove_certs,2,[{file,"ssl_pkix_db.erl"},{line,243}]},{ssl_connection,terminate,3,[{file,"ssl_connection.erl"},{line,935}]},{tls_connection,terminate,3,[{file,"tls_connection.erl"},{line,335}]},{gen_fsm,terminate,7,[{file,"gen_fsm.erl"},{line,610}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]},{gen_fsm,sync_send_all_state_event,[<0.461.0>,{start,30000},infinity]}}}}
apns app is started.
I made a guess, that my sertificates are encrypted - but public_key:pem_decode(CertBin)
returns []
on both key and cert files.
What should I do to make it working?
I moved to 1.0.5 and compiled and used apns*beams but I get following error in ejabberd logs
Would you be able to provide pointers on how to fix this?
Best Regards,
gen_fsm <0.412.0> in state certify terminated with reason: no function clause matching ssl_cipher:hash_algorithm(239) line 1174
2015-06-08 22:57:11.762 [error] <0.412.0> CRASH REPORT Process <0.412.0> with 0 neighbours exited with reason: no function clause matching ssl_cipher:hash_algorithm(239) line 1174 in gen_fsm:terminate/7 line 622
2015-06-08 22:57:11.763 [error] <0.99.0> Supervisor tls_connection_sup had child undefined started with {tls_connection,start_link,undefined} at <0.412.0> exit with reason no function clause matching ssl_cipher:hash_algorithm(239) line 1174 in context child_terminated
2015-06-08 22:57:11.763 [error] <0.409.0> CRASH REPORT Process <0.409.0> with 1 neighbours exited with reason: {{function_clause,[{ssl_cipher,hash_algorithm,"ï",[{file,"ssl_cipher.erl"},{line,1174}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,898}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,899}]},{ssl_handshake,decode_handshake,3,[{file,"ssl_handshake.erl"},{line,898}]},{tls_handshake,get_tls_handshake_aux,3,[{file,"tls_handshake.erl"},{line,153}]},{tls_connection,next_state,4,[{file,"tls_connection.erl"},{line,454}]},...]},...} in gen_server:init_it/6 line 328
2015-06-08 22:57:11.764 [error] <0.404.0> CRASH REPORT Process <0.404.0> with 0 neighbours exited with reason: no match of right hand value {error,{{function_clause,[{ssl_cipher,hash_algorithm,"ï",[{file,"ssl_cipher.erl"},{line,1174}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,898}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,899}]},{ssl_handshake,decode_handshake,3,[{file,"ssl_handshake.erl"},{line,898}]},{tls_handshake,get_tls_handshake_aux,3,[{file,"tls_handshake.erl"},{line,153}]},{tls_connection,next_state,4,[{file,"tls_connection.erl"},{line,...}]},...]},...}}
Make sure the repo is rebar3-compatible and its deps are also hex.pm packages, then publish it on hex.pm using inaka's hex.pm account.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.