113 Commits (master)

Author SHA1 Message Date
Jessie Murray dedfc42c67
WS: Log commands
WS client commands were not being logged, they are now with a "WS: "
prefix. This is done at debug level like for HTTP commands.
3 years ago
Jessie Murray 6b090b4ede
Large refactoring of WS code
1. Introduce ws_client struct
2. Handle all communications from websocket.c for WS clients
3. Always use a dedicated Redis connection for WS clients
4. Add rbuf & wbuf evbuffers for incoming & outgoing WS data
5. Use event_base_once to control R/W events
6. WS test: make sure to read complete HTTP response
3 years ago
Jessie Murray e26d6358e7
WS: Better reuse of the cmd struct for WS clients
For WS clients, reuse a persistent cmd struct attached to the
http_client object: take the cmd built from the WS frame, and copy it to
the persistent cmd.
3 years ago
Jessie Murray b98116abc8
Persistent cmd for WS, write buffer for responses
1. Only HTTP-based pub-sub clients were re-using a cmd object, but
   WS clients were not. This led to the commands sent by a WS client
   to be processed out of order, just queued to Redis but with no
   guarantee that they would be de-queued from the event loop in the
   same order. This change attaches a permanent cmd object (with its
   associated Redis context) to WS clients just like pub-sub clients
   do.

2. WS responses are also no longer sent out of order, but added to a
   write buffer that is scheduled for writing as long as there is still
   some data left to send. This replaces the use of http_response which
   contained extra fields (headers, HTTP response) that were duplicated
   without ever being sent out.
3 years ago
Jessie Murray 052458e876
Refactor WS code building raw http_response objects
Both ws_handshake_reply and ws_reply build http_response objects without
using the status code or headers, this code can be refactored to use a
single method.
3 years ago
Jessie Murray 27ad2413d4
Immediately close WS connection on error
The implementation was waiting for the client, which leaves some hanging
even after they called close(). This mirrors the behavior for HTTP
connections in client.c where close() is called right before
http_client_free.
3 years ago
Jessie Murray d0acdf030e
Report WS disconnection at DEBUG to avoid log spam 3 years ago
Jessie Murray 974556defb
WS headers: change order, make origin optional
1. Origin and Sec-WebSocket-Origin are now optional: only return a matching
Sec-WebSocket-Origin if one of the two headers was provided.
2. Change order of headers: return Sec-WebSocket-Accept immediately
   after Upgrade and Connection since some clients expect it there.
3 years ago
Jessie Murray 69be409b87
PR review: unused code, comment style 3 years ago
Jessie Murray 03ff07252e
Clean up http_response object when write cannot be scheduled
If the client closes the connection before we can even start to respond,
the event_add will fail and we need to clean up the http_response object
since this would have happened only after we've sent the whole response.
3 years ago
Jessie Murray 273e2a918d
Log on WS client error 3 years ago
Jessie Murray 8f70db179f
Send WS handshake using event loop instead of write(2)
ws_handshake_reply was sending its response using a single write(2) call
without error-checking, which could well send only part of it and leave
the client hanging. This change creates an HTTP response object and
schedules it for writing using the event loop.

Tested with Valgrind, no memory is leaked.
3 years ago
Jessie Murray e45779b303
Change TRACE log level to a value greater than was ever in webdis.json 3 years ago
Jessie Murray d5dc3d3ff0
Add more error-checking to WS handshake code 3 years ago
Jessie Murray c4ac66f78b
Remove extra trace logs in WS-related code 3 years ago
Jessie Murray a666d52471
Requested changes: logger
* Better log level check
* Add output letter for WEBDIS_TRACE logs
3 years ago
Jessie Murray b46bb8504b
Mark websocket http responses as keep_alive
The keep_alive flag is needed on http_response for websocket
connections. Without it, the server closes the connection as soon as a
reply to the first frame is sent.
3 years ago
Jessie Murray 873f1b5902
Add trace logs to websocket code, event loop functions
Mostly adding trace logs to websocket.c, but also some in http.c and
worker.c for events relating to event loop and client requests and
responses. This is useful for debugging websocket issues.
3 years ago
Jessie Murray 5a53c31a27
Logging improvements: add tracing, level check
* Add WEBDIS_TRACE log level for internal operations
* Warn when verbosity config is invalid
* Add slog_enabled to bypass buffer allocations if the level is filtered
3 years ago
Jessie Murray 0a27fc7e10
More progress on evbuffer-based WS client test 3 years ago
Nicolas Favre-Felix a0b19bac33
Version bump after release 3 years ago
Nicolas Favre-Felix 649cadcab7
Release 0.1.16
* Only process `Connection: close` header if full request was read
  (#194). This likely fixes the same issue also reported in #145.
* Fix small memory leak when the `type` query string parameter is
  used; the value was not being freed leading to growing memory usage
  of a few bytes per request. Upgrading is recommended if you use this
  feature.
* Fix invalid call to `ioctl`, which did not seem to affect Linux
  systems but could have had an impact on macOS (found in #197).
3 years ago
Nicolas Favre-Felix 950c5153d7
Fix invalid ioctl call
The `request` parameter is unsigned long, not int. This was invalid on
macOS and caused issues when sockets were considered non-blocking. Also
adds an error log if the call fails.

Thanks @likuilin for opening an issue that led to this discovery.
3 years ago
Nicolas Favre-Felix 66ef564b13
Fix memory leak in `?type=...` feature
Passing `?type=foo/bar` in the query string makes Webdis return the
response with a `Content-Type: foo/bar` header (this is useful to serve
files from Webdis, e.g. web page or their dependencies such as CSS,
images, etc). I discovered with Valgrind that the *value* of this query
string parameter was leaked and never freed, which would likely not
cause a huge issue but would still gradually grow the memory usage.

There were 2 different functions taking care of this parameter, the
first calling strdup(3) on it and the second *transferring* pointer
ownership into it (meaning overwriting the just-strdup'd value).

This is now fixed, Webdis no longer leaks this small string, and an
allocation was avoided.
3 years ago
Jessie Murray 6556039e05
Only process `Connection: close` header if full request was read (fixes #194) (#195) 3 years ago
Nicolas Favre-Felix 0e6ef3f7c9
Version bump after release 3 years ago
Nicolas Favre-Felix d988eea778
Release 0.1.15
* Fixed compilation warnings
* Fixed code quality issues found by CodeQL
* Upgraded base image from alpine:3.12.6 to alpine:3.12.7
  See CWE-125 and CVE-2021-30139). This is *not* a security issue if
  you just use the webdis image to run the service, but could be if
  you're building a new Docker image using webdis as a base image.
3 years ago
Nicolas Favre-Felix c0329d7813
Remove old .gitignore from Jansson
This was causing jansson_config.h to be excluded when the repo was
cloned with certain git pull commands.
3 years ago
Jessie Murray d1f4b831d9
CodeQL fixes (#192)
* CodeQL: overrunning write in jansson/dump.c
* CodeQL: overrunning write in http.c
* CodeQL: redundant condition in websocket.c
* CodeQL: redundant condition in jansson/utf.c
* CodeQL: File created without restricting permissions in server.c
* CodeQL: Futile conditional in pool.c
* CodeQL: Too many arguments in jansson/load.c
* CodeQL: Commented-out code in http.c
* Jansson: disable truncation warning locally in error reporting function
3 years ago
Nicolas Favre-Felix 60c224e667
Post-release version bump and README update 4 years ago
Nicolas Favre-Felix c52f6374b5
Release 0.1.14
* Fixed compilation warnings
* Fsync frequency for log file is now configurable
* Added support for REPLY_STATUS in nested JSON objects (helps with
  RediSearch)
4 years ago
Jessie Murray 1cd2a8b934
Add support for REDIS_REPLY_STATUS in nested JSON (#189)
When strings are added as elements of an array but typed as
REDIS_REPLY_STATUS instead of REDIS_REPLY_STRING, Webdis encodes them as
nulls. REDIS_REPLY_STATUS should only be encoded as [true, str] or
[false, str] when this is a top-level status response, not an array
element. In these cases we only need the string.

Fixes #188
4 years ago
Jessie Murray 53f483fb6a
Make fsync frequency configurable for log file (#187)
Webdis used to call fsync after every single log message, which had a
significant negative impact on performance. This change introduces 3
config options for fsync: no explicit fsync (the new default), a periodic
fsync called every N milliseconds, or the old behavior.

The new config key is also documented and validates its inputs.
4 years ago
Jessie Murray 2e71e85f4f Add explicit cast to msgpack callback 4 years ago
Jessie Murray efbd274294 Add "fall through" comments in switch to disable warning 4 years ago
Jessie Murray 24b09bb372 Remove strncpy false positive warning in slog.c
Use memcpy instead
4 years ago
Jessie Murray 34c51efc5e Add __attribute__ ((unused)) in dict.c
Checks for __GNUC__ to see if __attribute__ is available
4 years ago
Jessie Murray e3a29117e7 Fix warnings in conf.c
1. Remove unused size_t sz variable
2. Remove const on free()'d variable
4 years ago
Nicolas Favre-Felix c6d5d20de7
Post-release version bump and README update 4 years ago
Nicolas Favre-Felix d7738afd58
Release 0.1.13
* Adds support for Redis 6.0 auth
* Fixes one-time leak of 26 bytes when reading the config file
4 years ago
Jessie Murray 4bc0871006
Fix small leaks in conf.c (fixes #184) (#185)
1. plaintext was not free'd after encoding credentials
2. ACL commands were duplicated when there was no need to

In both cases the value came from conf_string_or_envvar which always
uses strdup.
4 years ago
Jessie Murray fd3ec5d3ba Fixes for PR #183
Stop logging an error when auth is disabled and free all the fields of
redis_auth.
4 years ago
Jessie Murray 0177479cc5 Log Redis auth response
We were ignoring the response sent by Redis for AUTH commands. This
commit adds a callback which logs the response; I've tested it with
valid and invalid credentials and the log message is correct in both
cases. There's a lock on the server object to only log this once; I
tried adding it on the pool object but there's one pool per thread so
we still ended up with multiple messages.
4 years ago
Jessie Murray 09bd76f3a8 slog.c: Change level symbol to a single letter
A single symbol was added to the log depending on the level, one of ".-*#"
This had an issue: there were only 4 symbols but there are 5 levels; in
addition a `%b` was used which logged a number instead of a letter.
This commit changes the logic to add a single uppercase letter instead,
based on the level (e.g. WEBDIS_ERROR is E, _INFO is I, etc.)
4 years ago
Jessie Murray 02d60dc548 Implement Redis v6 auth (fixes #182)
* Change redis_auth in struct conf to handle old and new auth
* Update cfg.c to understand an array of two strings for redis_auth
* Update pool.c to send both username and password
4 years ago
Nicolas Favre-Felix 7e1c344259
Version bump after release 4 years ago
Nicolas Favre-Felix 21586199da
Release 0.1.12
* Adds support for MsgPackC on macOS
* Tests now pass with with python-msgpack (#150)
4 years ago
Nicolas Favre-Felix 1589b77da9
Clean up empty indented lines 4 years ago
Jessie Murray b3868d81d8 CodeQL: apply recommendations
* Use `localtime_r` instead of `localtime`
* Use correct argument type in callback to `msgpack_packer_new`
* Address FIXME in conf.c
* Remove redundant check in websocket.c
4 years ago
Nicolas Favre-Felix c4ca659c4c Version bump after release 4 years ago
Nicolas Favre-Felix ceec7748dd Release 0.1.11 4 years ago
Nicolas Favre-Felix 64d545cd64 Formatting fixes and object key changes for nested arrays
Formatting changes:
* Added `{}` after each single-line `if` (see "goto fail" bug).
* Added spaces around operators

Object key changes: reviewed the docs and selected more appropriate
names for various object keys.
4 years ago
majklik 106ae2433a
Few typos 4 years ago
majklik 69b1248626
JSON nested arrays
Add support for nested arrays and some commands replies areconverted into MAPs.
4 years ago
Nicolas Favre-Felix 3a39be4a2d Version bump after release 4 years ago
Nicolas Favre-Felix 77776e0eaa Release 0.1.10 4 years ago
Jessie Murray 1872facb48 Support environment variables in the config
* Adds support for environment variables in webdis.json
* Values starting with a `$` and in all caps are interpreted as
environment variables
4 years ago
Andrii Senkovych de22444576 Print HTTP port number in the logs during startup.
This provides a way to start webdis with dynamic port allocation and
discover HTTP port number by simply grepping logs i.e. without need to
use netstat or sockstat that are not available on some architectures.

Dynamic port allocation is a feature that can be used to run webdis
ad-hoc for testing purpose.
5 years ago
Nicolas Favre-Felix bb64f3bba7 Version bump after release 5 years ago
Nicolas Favre-Felix 0651736551 Release 0.1.9 5 years ago
Nicolas Favre-Felix 00b5188e85 Merge branch 'new-msgpack' of https://github.com/jamessan/webdis into jamessan-new-msgpack 5 years ago
Nicolas Favre-Felix ee6c564991 Version bump after release 5 years ago
Nicolas Favre-Felix 7add4cc30b Release 0.1.8 5 years ago