asterisk/res/ari
Matthew Jordan 365ae7523b res_http_websocket: Close websocket correctly and use careful fwrite
When a client takes a long time to process information received from Asterisk,
a write operation using fwrite may fail to write all information. This causes
the underlying file stream to be in an unknown state, such that the socket
must be disconnected. Unfortunately, there are two problems with this in
Asterisk's existing websocket code:
1. Periodically, during the read loop, Asterisk must write to the connected
   websocket to respond to pings. As such, Asterisk maintains a reference to
   the session during the loop. When ast_http_websocket_write fails, it may
   cause the session to decrement its ref count, but this in and of itself
   does not break the read loop. The read loop's write, on the other hand,
   does not break the loop if it fails. This causes the socket to get in a
   'stuck' state, preventing the client from reconnecting to the server.
2. More importantly, however, is that the fwrite in ast_http_websocket_write
   fails with a large volume of data when the client takes awhile to process
   the information. When it does fail, it fails writing only a portion of
   the bytes. With some debugging, it was shown that this was failing in a
   similar fashion to ASTERISK-12767. Switching this over to ast_careful_fwrite
   with a long enough timeout solved the problem.

Note that this version of the patch, unlike r417310 in Asterisk 11, exposes
configuration options beyond just chan_sip's sip.conf. Configuration options
to configure the write timeout have also been added to pjsip.conf and ari.conf.

#ASTERISK-23917 #close
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/3624/
........

Merged revisions 417310 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 417311 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@417317 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-26 12:21:14 +00:00
..
ari_model_validators.c TALK_DETECT: A channel function that raises events when talking is detected 2014-05-30 12:42:57 +00:00
ari_model_validators.h TALK_DETECT: A channel function that raises events when talking is detected 2014-05-30 12:42:57 +00:00
ari_websockets.c res_http_websocket: Close websocket correctly and use careful fwrite 2014-06-26 12:21:14 +00:00
cli.c Rename everything Stasis-HTTP to ARI 2013-07-27 23:11:02 +00:00
config.c res_http_websocket: Close websocket correctly and use careful fwrite 2014-06-26 12:21:14 +00:00
internal.h res_http_websocket: Close websocket correctly and use careful fwrite 2014-06-26 12:21:14 +00:00
resource_applications.c res_ari: Fix various memory leaks. 2014-01-12 22:24:27 +00:00
resource_applications.h ARI: Support channel variables in originate 2014-01-21 14:27:21 +00:00
resource_asterisk.c ari: User better nicknames for ARI operations 2013-11-07 21:10:31 +00:00
resource_asterisk.h ARI: Support channel variables in originate 2014-01-21 14:27:21 +00:00
resource_bridges.c ARI: Make bridges/{bridgeID}/play queue sound files 2014-04-18 20:09:24 +00:00
resource_bridges.h ARI: Make bridges/{bridgeID}/play queue sound files 2014-04-18 20:09:24 +00:00
resource_channels.c stasis: Reduce creation of channel snapshots to improve performance 2014-06-13 18:24:49 +00:00
resource_channels.h ARI: Add tones playback resource 2014-04-17 21:57:36 +00:00
resource_device_states.c res_ari: Fix various memory leaks. 2014-01-12 22:24:27 +00:00
resource_device_states.h ARI: Support channel variables in originate 2014-01-21 14:27:21 +00:00
resource_endpoints.c json: Fix off-nominal json ref counting issues. 2014-02-21 18:04:54 +00:00
resource_endpoints.h ari: User better nicknames for ARI operations 2013-11-07 21:10:31 +00:00
resource_events.c ARI: Add ability to raise arbitrary User Events 2014-05-22 16:09:51 +00:00
resource_events.h ARI: Add ability to raise arbitrary User Events 2014-05-22 16:09:51 +00:00
resource_mailboxes.c ARI: Add mailboxes resource for controlling and polling external MWI 2014-01-14 23:44:57 +00:00
resource_mailboxes.h ARI: Support channel variables in originate 2014-01-21 14:27:21 +00:00
resource_playbacks.c res_ari: Fix various memory leaks. 2014-01-12 22:24:27 +00:00
resource_playbacks.h ARI: Support channel variables in originate 2014-01-21 14:27:21 +00:00
resource_recordings.c Remove unused RAII_VAR() declarations. 2014-04-15 18:01:47 +00:00
resource_recordings.h ari: User better nicknames for ARI operations 2013-11-07 21:10:31 +00:00
resource_sounds.c ari: User better nicknames for ARI operations 2013-11-07 21:10:31 +00:00
resource_sounds.h ARI: Support channel variables in originate 2014-01-21 14:27:21 +00:00