~rockorager/go-jmap-devel

go-jmap: client: lock mutex after calling Authenticate when uploading/downloading v1 PROPOSED

Silvan Jegen: 1
 client: lock mutex after calling Authenticate when uploading/downloading

 1 files changed, 4 insertions(+), 0 deletions(-)
In JMAP, each request returns the state string of the session object. I've found
it to be pretty good practice to check that on every request against the session
object you have, and if it's different, request a new session object. In this
case, that would be to call Authenticate.

If we remove that method, the only means is to then create a *new* client. This
has *some* performance hit because the old client would have been maintaining
the connections - while a new one would have to renegotiate TLS, etc.
Next
"Tim Culverhouse" <tim@timculverhouse.com> wrote:
Next
"Tim Culverhouse" <tim@timculverhouse.com> wrote:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rockorager/go-jmap-devel/patches/56765/mbox | git am -3
Learn more about email & git

[PATCH go-jmap] client: lock mutex after calling Authenticate when uploading/downloading Export this patch

This makes sure we don't end up Unlocking an unlocked mutex while
also covering the critical section where we access the Session's
Upload/Download URLs.
---
 client.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/client.go b/client.go
index 33aa553..b0c461f 100644
--- a/client.go
+++ b/client.go
@@ -192,6 +192,8 @@ func (c *Client) UploadWithContext(
		if err != nil {
			return nil, err
		}

		c.Lock()
	}

	url := strings.ReplaceAll(c.Session.UploadURL, "{accountId}", string(accountID))
@@ -246,6 +248,8 @@ func (c *Client) DownloadWithContext(
		if err != nil {
			return nil, err
		}

		c.Lock()
	}

	urlRepl := strings.NewReplacer(
-- 
2.47.1
Silvan Jegen <s.jegen@gmail.com> wrote: