Commit Graph

38 Commits

Author SHA1 Message Date
Eklavya Sharma dca9256f3c zerver/lib/socket.py: Improve annotations.
* Add Optional where required.
* Set type of req_redis_key as `(text_type) -> text_type` for consistency.
  Almost all our cache keys and redis keys use this signature.
2016-06-29 00:45:13 +05:30
Conrad Dean 33dee43179 Annotate zerver/lib/socket.py.
Currently this uses a Union type for connection_id; we need to figure
out what actually sets that and what its type is and fix that later
(see https://github.com/zulip/zulip/issues/896).
2016-06-04 22:36:03 -07:00
Tim Abbott b869be9301 style: Use 'not in' consistently rather than `not foo in`. 2016-05-09 17:00:10 -07:00
Tim Abbott 4219a6779f socket: Initialize client_id to None by default.
This fixes an exception where client_id was never set in an error code
path.  It shouldn't be needed, but I think this makes the code clearer
and this will help in debugging the actual problem.

Related to #753.
2016-05-05 14:49:26 -07:00
Varshit 4e1060076d Purge 'from typing import *' from zerver/.
This is a partial implementation of #636.
2016-04-07 14:07:07 -07:00
Tim Abbott 2059f650ab Add PEP-484 type annotations to zerver/lib/. 2016-04-03 15:40:23 -07:00
Tim Abbott b99313545e Add PEP-484 type annotations to global dictionaties. 2016-04-03 15:40:06 -07:00
Reid Barton 9db521a931 Django 1.8 compatibility: extracting the user from a session
django commit 596564e80808 stores the user id in the session as a
string, which broke our code that extracts the user id and compares
it to the id of a UserProfile object.

(imported from commit 99defd7fea96553550fa19e0b2f3e91a1baac123)
2015-08-20 23:15:45 -07:00
Zev Benjamin 6691789cce Add helper function for returning a Redis client
(imported from commit 47f87d388d24343ac6b631181a55287eb8cd4a6d)
2014-02-10 13:23:28 -05:00
Leo Franchi 56d9446c41 [socket] Use socket req ids that contain queue ids
(imported from commit 781eafe60bf117d79ce3a30deea02ec1e875060a)
2014-01-23 16:28:58 -05:00
Leo Franchi 7743aa191c Pass through local_id and sender_queue_id in non-rabbitmq case
(imported from commit 8989225a0943b39e45bd5debe405acb9768acc8c)
2014-01-23 16:28:58 -05:00
Tim Abbott a70072f5cf socket: Don't throw traceback when sessions are expired.
(imported from commit 16c876b5bbd0c6ecd5ef48369a7f71ca74d1183f)
2013-12-19 16:52:53 -05:00
Zev Benjamin 0d989a6972 socket: Close old connections before registering new ones under the same id
(imported from commit f9b75288cbf7e2d9baa3254d57443eea5c1f3fc3)
2013-12-09 16:17:26 -05:00
Zev Benjamin 5e19ad31bf socket: Increase redis response cache expiration time
(imported from commit 1b18530f01499af9a555c71f0281e62bd3164542)
2013-12-08 12:13:15 -05:00
Zev Benjamin 96bb739157 socket: Add some server-side logging for bug catching
(imported from commit 8579d8bbb414b063ae9cf36993975adaa86cb132)
2013-12-06 16:22:24 -05:00
Zev Benjamin 8535669d46 socket: Include the user in socket close log lines
(imported from commit fb5b9e54a07b6bfd85e913b8c97105305f8210eb)
2013-12-06 16:22:24 -05:00
Zev Benjamin 657a750550 socket: Fix spelling
We don't ever actually check for this value so nothing else has to
change.

(imported from commit e6ccb153df7bd95c9d195aa83395592b309a2778)
2013-12-05 15:53:50 -05:00
Zev Benjamin 002df64811 Remove extraneous semicolons
(imported from commit 2077705c52e7255ab7ea1b4df71d2ae99f6018dc)
2013-12-05 15:53:50 -05:00
Zev Benjamin bc43981ccf socket: Explain why we disable some transports
(imported from commit 670d2f558a11a6f4fcce3f2e107582c4425b9285)
2013-11-25 11:58:02 -05:00
Zev Benjamin 15a837d12e [manual] socket: Send explicit ACKs
There will be browser errors on staging when this is deployed due to the socket
protocol changing.

(imported from commit f1eda5b5c2ec9c60c23b3ca96277a61debadf5bb)
2013-11-19 11:06:14 -05:00
Zev Benjamin 7870b4d158 socket: Fix a traceback on server restart
I believe there may also be others.  I'm still not sure why clients would be
sending open requests without session or csrf values in their cookies, though.

(imported from commit 7e9660c1c4d5c2abf55ff21b433ba0117180eb82)
2013-11-19 11:06:13 -05:00
Zev Benjamin 5c6a85f99a socket: Change path for 'not yet authenticated' error messages
(imported from commit 826d3a0ea9084644810a00a14f2f19936e21118c)
2013-11-18 11:42:57 -05:00
Zev Benjamin 319852c60e socket: Fix keyword argument name for error logging
(imported from commit e61eace1aa48fe17d5d2338f7990e32d3404d390)
2013-11-18 11:42:57 -05:00
Zev Benjamin cf8cf1fe03 socket: Fix non-rabbitmq codepath
(imported from commit 3ccdcbfb3283fc57ca502878e9c8d6068e7bce40)
2013-11-12 16:42:15 -05:00
Zev Benjamin 673f497a6f socket: Only deregister connections that have been registered
(imported from commit bfaed299a129bac1e901883f5c6e3339f5a8b688)
2013-11-12 15:24:30 -05:00
Zev Benjamin eec195f421 socket: Use our full logging infrastructure
We also now separate out the times for the socket overhead, the
request service time, and the queuing delays.

(imported from commit e1683f7f28b968b86ebb701b0ac29b00ac6d67c3)
2013-11-12 15:24:30 -05:00
Zev Benjamin 24ee4a5d57 socket: Build a real Request object to send through our full stack, including middleware
One quirk here is that the Request object is built in the
message_sender worker, not Tornado.  This means that the request time
only counts time taken for the actual sending and does not account
for socket overhead.  For this reason, I've left the fake logging in
for now so we can compare the two times.

(imported from commit b0c60a3017527a328cadf11ba68166e59cf23ddf)
2013-11-12 15:24:29 -05:00
Zev Benjamin 24ae5998e5 socket: Request the status of pending requests on reconnect
This will hopefully help with the send dialog being stuck on
"sending" as well as allowing us to not show errors to the user on
reconnect.

(imported from commit 31ee889853f348e486863073dc130cdfb4e1338d)
2013-11-07 11:43:34 -05:00
Zev Benjamin 48a25211fa socket: Record the request status in redis
(imported from commit 6c3f6dc37d1abdcacf105f865ac24483717438ca)
2013-11-07 11:43:34 -05:00
Zev Benjamin 87fc182645 socket: Move `req_id` parameter to top level of protocol payload
(imported from commit 271d84a0b44a2623bec290f64a83a0423698a1ef)
2013-11-07 11:43:34 -05:00
Zev Benjamin 4595143023 socket: Switch to client ids from connection ids
Clients can only have one connection at a time, anyway, so we can
just keep track of a client id, instead.  This makes reconnections
easier.

It's a little funny to use queue ids for the client id, but we know
they should exist by the time the client is connecting and they are
guaranteed to already be unique and authenticatable.  We will also
eventually be integrating the event system and the socket code closer
anyway.

(imported from commit 1f60e06fb16d31d6c121deafd493fb304d19a6c2)
2013-11-07 11:43:34 -05:00
Zev Benjamin 63924ea742 socket: Reduce code duplication in authentication error cases
(imported from commit e7900b1374c3c0e5ea994ff315d281833e7ecdc6)
2013-11-07 11:37:00 -05:00
Zev Benjamin e0fece4082 socket: Log the transport type on the authentication line
(imported from commit 7b3ae3ab38da35cbd60aca991665d40b41a7f78f)
2013-11-07 11:31:06 -05:00
Steve Howell 70c1c31b3a Simplify callback protocol for register_json_consumer().
The register_json_consumer() function now expects its callback
function to accept a single argument, which is the payload, as
none of the callbacks cared about channel, method, and properties.

This change breaks down as follows:

    * A couple test stubs and subclasses were simplified.
    * All the consume() and consume_wrapper() functions in
      queue_processors.py were simplified.
    * Two callbacks via runtornado.py were simplified.  One
      of the callbacks was socket.respond_send_message, which
      had an additional caller, i.e. not register_json_consumer()
      calling back to it, and the caller was simplified not
      to pass None for the three removed arguments.

(imported from commit 792316e20be619458dd5036745233f37e6ffcf43)
2013-10-31 13:18:11 -04:00
Leo Franchi 9be1333c6b Log send_message times through our new socket infrastructure as well
(imported from commit 215be8f7e3d2498ed34e9fcc421498a7cfca4fbc)
2013-10-29 17:49:27 -04:00
Zev Benjamin b1eebc0b84 Deliver messages inside Tornado when running tests
This saves us from having to run queue processors while testing.

(imported from commit 927bfa497a47b34603761a148c57d82b2f34f813)
2013-10-22 18:45:11 -04:00
Zev Benjamin 3c73468ba8 Disable unsupported SockJS transports
Because our authentication system reads cookies from the initial
connection attempt, several SockJS transports can't be used.

(imported from commit 34b9571225d39072985b8223fb12c43c7235841f)
2013-10-22 18:45:11 -04:00
Zev Benjamin 5979af3a45 [manual] Add asynchronous message sender via sockjs-tornado
New dependency: sockjs-tornado

One known limitation is that we don't clean up sessions for
non-websockets transports.  This is a bug in Tornado so I'm going to
look at upgrading us to the latest version:
https://github.com/mrjoes/sockjs-tornado/issues/47

(imported from commit 31cdb7596dd5ee094ab006c31757db17dca8899b)
2013-10-22 18:45:11 -04:00