Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection minor fixes #953

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

zuiderkwast
Copy link
Contributor

  1. Remove redundant connIncrRefs/connDecrRefs

    In socket.c, the reference counter is incremented before calling callHandler, but the same reference counter is also incremented inside callHandler before calling the actual callback.

     static inline int callHandler(connection *conn, ConnectionCallbackFunc handler) {
         connIncrRefs(conn);
         if (handler) handler(conn);
         connDecrRefs(conn);
         ...
     }
    

    This commit removes the redundant incr/decr calls in socket.c

  2. Correct return value of connRead for TLS when peer closed

    According to comments in connection.h, connRead returns 0 when the peer has closed the connection. This patch corrects the return value for TLS connections. (Without this patch, it returns -1 which means error.)

    There is an observable difference in what is logged in the verbose level: "Client closed connection" vs "Reading from client: (null)".

In socket.c, the reference counter is incremented before calling callHandler, but the same reference counter is also incremented inside callHandler before calling the actual callback.

    static inline int callHandler(connection *conn, ConnectionCallbackFunc handler) {
        connIncrRefs(conn);
        if (handler) handler(conn);
        connDecrRefs(conn);
        ...
    }

This commit removes the redundant incr/decr calls in socket.c

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
According to comments in connection.h, connRead returns 0 when the peer has closed the connection. This patch corrects the return value for TLS connections. (Without this patch, it returns -1 which means error.)

There is an observable difference in what is logged in the verbose level: "Client closed connection" vs "Reading from client: (null)".

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
@zuiderkwast
Copy link
Contributor Author

These minor fixes were written in January and already reviewed by @enjoy-binbin.

Copy link
Member

@enjoy-binbin enjoy-binbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.43%. Comparing base (04d76d8) to head (10fe21e).
Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #953      +/-   ##
============================================
- Coverage     70.43%   70.43%   -0.01%     
============================================
  Files           113      113              
  Lines         61728    61725       -3     
============================================
- Hits          43479    43474       -5     
- Misses        18249    18251       +2     
Files Coverage Δ
src/socket.c 91.12% <ø> (-0.16%) ⬇️
src/tls.c 100.00% <ø> (ø)

... and 11 files with indirect coverage changes

@zuiderkwast zuiderkwast merged commit 54c0f74 into valkey-io:unstable Aug 27, 2024
47 checks passed
@zuiderkwast zuiderkwast deleted the connection-minor-fixes branch August 27, 2024 14:11
madolson pushed a commit that referenced this pull request Sep 2, 2024
1. Remove redundant connIncrRefs/connDecrRefs

    In socket.c, the reference counter is incremented before calling
callHandler, but the same reference counter is also incremented inside
callHandler before calling the actual callback.

        static inline int callHandler(connection *conn, ConnectionCallbackFunc handler) {
            connIncrRefs(conn);
            if (handler) handler(conn);
            connDecrRefs(conn);
            ...
        }

    This commit removes the redundant incr/decr calls in socket.c

2. Correct return value of connRead for TLS when peer closed

    According to comments in connection.h, connRead returns 0 when the peer
has closed the connection. This patch corrects the return value for TLS
connections. (Without this patch, it returns -1 which means error.)

    There is an observable difference in what is logged in the verbose
level: "Client closed connection" vs "Reading from client: (null)".

---------

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
madolson pushed a commit that referenced this pull request Sep 3, 2024
1. Remove redundant connIncrRefs/connDecrRefs

    In socket.c, the reference counter is incremented before calling
callHandler, but the same reference counter is also incremented inside
callHandler before calling the actual callback.

        static inline int callHandler(connection *conn, ConnectionCallbackFunc handler) {
            connIncrRefs(conn);
            if (handler) handler(conn);
            connDecrRefs(conn);
            ...
        }

    This commit removes the redundant incr/decr calls in socket.c

2. Correct return value of connRead for TLS when peer closed

    According to comments in connection.h, connRead returns 0 when the peer
has closed the connection. This patch corrects the return value for TLS
connections. (Without this patch, it returns -1 which means error.)

    There is an observable difference in what is logged in the verbose
level: "Client closed connection" vs "Reading from client: (null)".

---------

Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants