1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00
Commit graph

72 commits

Author SHA1 Message Date
Will Dollman
e4e2e6324c Update security policy to use email for reporting 2023-09-25 11:50:00 +01:00
Diogo Teles Sant'Anna
510183e882
Create Security Policy 2023-09-11 14:51:22 -03:00
Diogo Teles Sant'Anna
8a0bf06edf
ci: set minimal permissions to GitHub workflows (#73)
Signed-off-by: Diogo Teles Sant'Anna <diogoteles@google.com>
2023-08-30 09:07:57 +02:00
Fazlul Shahriar
b9c1fbdb96
Fix logging of received response messages (#71)
As documented: OnRecv causes all requests received on conn to invoke
f(req, nil) and all responses to invoke f(req, resp).

Since OnRecv is called with both *Request and *Response being non-nil
when we're handling a response, we need to check that *Response is
non-nil before we check *Request is non-nil. This change just swaps the
two cases in the switch statement to fix the issue. For consistency,
I've swapped the cases for OnSend also, even when it's not needed.
2023-07-14 13:00:57 +02:00
Keegan Carruthers-Smith
5d80b29f44
conn: do not lock sending when closing (#70)
The sending mutex may be blocked due to the underlying conn blocking. If
that happens then we can't call close since close also attempts to hold
the sending mutex. Sending mutex is only used for serializing sends and
doesn't protect the fields close reads/writes. I believe we introduced
locking it so we would return ErrClosed. This commit instead introduces
a check in send which rechecks if we have since closed while attempting
to send.

Test Plan: expanded the test coverage
2023-06-07 08:40:20 +02:00
Sam Herrmann
040dc22f8a
Add package example test (#68) 2023-03-01 06:46:15 +02:00
Sam Herrmann
ae88a5e7c0
Always omit params member from request when empty (#67)
With this commit, the JSON encoding of `Request` always omits the params
member when calling `Conn.Call`, `Conn.DispatchCall`, or `Conn.Notify`
with the `params` argument set to `nil`. This change also removes the
`OmitNilParams` call option that was added in commit 8012d496 (#62).

As of this commit, if users desire to send a JSON-RPC request with a
`params` value of `null`, then they may do so by explicitly setting the
`params` argument of `Conn.Call`/`Conn.DispatchCall`/`Conn.Notify` to
`json.RawMessage("null")`.
2023-02-22 10:53:44 +02:00
Sam Herrmann
6864d8cc6d
Omit data field from error when empty (#66)
The JSON-RPC 2.0 specification allows the data member of an error object
to be omitted. Before this commit, if Error.Data was nil then the JSON
encoding was "null". That means that the data member was included in
every JSON-RPC error object, even when the data member was not
explicitly set.

This commit adds the omitempty struct tag to the Error.Data field,
meaning that the data member is omitted from the JSON encoding unless
explicitly set with the Error.SetError() method. Beware that this is a
breaking change for clients that may have strict null checks on the data
member.
2023-02-12 14:52:17 +02:00
Sam Herrmann
846c29e96d
Split jsonrpc2.go file into multiple files (#65)
This merge request moves some of the contents from the jsonrpc2.go file
into their own designated file. The new files being introduced
(excluding test files) are as follows:

* conn.go
* request.go
* response.go

The motive of this change is to make it easier to navigate the code.
Without this change, the jsonrpc2.go file is 813 lines of code.
2023-02-09 07:56:42 +01:00
Sam Herrmann
028a50bb39
Fix underlying connection not being closed on protocol error (#64)
Before this commit, the underlying connection of `Conn` was not being
closed when a protocol error was encountered. This behavior contradicted
with `Conn.DisconnectNotify()` because it reported that the underlying
connection was being closed. Additionally, the underlying connection was
now orphaned because `Conn` was no longer processing any of the
subsequent requests.

With this commit, the underlying connection is now being closed when a
protocol error is encountered, matching what `Conn.DisconnectNotify()`
has already been reporting.
2023-02-07 21:46:05 +01:00
Sam Herrmann
78a3d790f3
Pin staticcheck version to v0.2.2 (#63)
The CI pipeline has been broken in this project for some time because
the latest version of staticcheck is not compatible with every version
of Go. Through trial and error, it was discovered that staticcheck
v0.2.2 is the latest version that is compatible with Go 1.16.

The authors of staticcheck also recommend pinning the version in CI
pipelines to prevent unintentional breakage of the build [1].

References
[1]: https://staticcheck.io/docs/running-staticcheck/ci/github-actions/#version
2023-02-03 10:51:22 +02:00
Sam Herrmann
8012d49686
Add ability to omit params member from request (#62)
The JSON-RPC 2.0 specification allows the params member of a request to
be omitted [1]. Before this commit, this library did not allow the
params member to be omitted when sending a request. When the params
argument of the Conn.Call/Conn.DispatchCall or Conn.Notify method was
set to nil, then Request.Params was set to the JSON encoding of nil
which is null.

This commit adds a CallOption named OmitNilParams. If OmitNilParams is
used when sending a request with params set to nil, then the params
member in the JSON encoding of Request is omitted. If the OmitNilParams
option is not used then the previous behavior is maintained. In other
words, the changes in this commit are backwards compatible.

References
[1]: https://www.jsonrpc.org/specification#request_object
2023-01-24 08:47:36 +02:00
Semesse
e1f9fdf1bb
fix no corresponding request if req.ID is modified by onSend (#60) 2023-01-13 20:33:58 +02:00
Dax McDonald
065a868115
Merge pull request #59 from sourcegraph/batch-changes/dax/update-checkout-v3
ci: update to actions/checkout@v3
2023-01-05 07:22:44 -08:00
Sourcegraph
7f448843ac batch changes - update checkout v2 to v3 2023-01-03 22:03:16 +00:00
Michał Nowotnik
a896fc3eac
[#57] Fix and deprecate PlainObjectCodec (#58)
This change fixes a bug that causes PlainObjectCodec to
lose additional messages from stream. json.Decoder has
an internal buffer that reads more than one message, but
is discarded after every use. Now PlainObjectCodec reuses
encoder and decoder within a buffered stream, however
using it directly in your code retains the old, incorrect
behaviour.

A user should now use plainObjectStream if he needs
plain JSON-RPC 2.0 stream without headers.
`NewPlainObjectStream` method has been added for this reason.
2022-07-11 15:43:39 +02:00
Sam Herrmann
c9c77b6bb9
Add ability to set custom logger (#48)
Before this commit, a custom logger could be set with the LogMessages
function. However, by using LogMessages not only is a custom logger set
but also all received and sent messages are logged. Use cases exist
where a custom logger is desired to log errors but not all messages.
2021-11-19 10:30:03 +02:00
lhchavez
5f298fe6a1
Homogenize treatment of params and meta in UnmarshalJSON (#52)
This change makes the treatment of params and meta the same, by
assigning a well-known pointer at first to detect if the unmarshaling
process overwrites it with an explicit nil, or it stays the same in
which it means that it was unset from the beginning.
2021-08-04 18:55:02 +02:00
lhchavez
120d461fd1
Add GitHub actions (#51)
That extra green checkmark does wonders for peace of mind.
2021-08-04 14:46:32 +02:00
lhchavez
d6ac66e24f
Add a way to specify more non-standard-compliant fields to Request (#50)
This change introduces `ExtraField`, a `CallOption` that can add
arbitrary fields to the top-level JSON-RPC Request message.
2021-08-04 14:45:59 +02:00
amyxia
5cdc7d6ccd
fix typo in jsonrpc2/stream.go (#47)
Co-authored-by: xiarui.xr <xiarui.xr@antfin.com>
2021-05-26 14:52:51 +02:00
Sam Herrmann
99f63e011f
Add PlainObjectCodec (#45) 2021-04-26 09:13:34 +02:00
Sam Herrmann
08fd77d0de
Add StringID call option (#44)
Fixes #43
2021-04-26 09:12:26 +02:00
Cornelius Weig
366fbb5207
Break the Call method into a dispatcher and waiter (#41)
Before, the Call method dispatched the JSON-RPC request and waited
until completion of the request before returning. This made it difficult
to release any locks that need to be released upon dispatch.

Now, the Call method is broken into a DispatchCall and Wait pair.
DispatchCall returns a proxy to the internal call object as soon as the
request is dispatched. When appropriate, the caller can invoke the Wait
method on this proxy to block until the result is ready.

The original Call method is not changed, but now implemented by
these primitives.
2021-02-01 10:28:50 +02:00
garo (they/them)
15c2290dcb
update LSIF indexing CI workflow 2020-04-29 14:40:54 -04:00
Sourcegraph Bot
9e615b1c32 LSIF Indexing Campaign 2020-04-29 16:57:20 +00:00
Quinn Slack
96c4efab7e
Produce LSIF data for each commit for fast/precise code nav (#35)
* Produce LSIF data for each commit for fast/precise code nav

* Update lsif.yml
2019-12-21 20:34:38 -08:00
Quinn Slack
cee7209801
minor logging fixes (#34)
minor logging fixes
2019-11-13 00:00:33 -08:00
s3rj1k
81af42d766 minor logging fixes
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-07 23:44:16 +02:00
s3rj1k
3bf62ad25c fix Using a reference for the variable on range scope (#32)
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-04 13:57:41 -08:00
Quinn Slack
9d396041a5
Merge pull request #31 from s3rj1k/logger
use custom logger for internal logging
2019-11-03 21:31:32 -08:00
s3rj1k
76d435e06e support for go 1.12+ (#30) 2019-11-03 12:56:29 -08:00
s3rj1k
6053545ad1 use custom logger for internal logging
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-03 22:30:34 +02:00
s3rj1k
0f50d0d83e fix File is not goimports-ed (#28)
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-03 11:41:16 -08:00
Quinn Slack
8819199291
fix some golangci-lint, revive linter warnings (#25)
fix some golangci-lint, revive linter warnings
2019-11-02 21:42:37 -07:00
Quinn Slack
375ca94e9c add go module, simplify some cleanups 2019-11-02 21:39:58 -07:00
s3rj1k
456318691a fix some golangci-lint, revive linter warnings
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-02 22:31:31 +02:00
Quinn Slack
35a74f039c
Merge pull request #23 from ggicci/master
Prevent program from panic on nil options
2019-01-06 12:59:02 -06:00
Ggicci
3e2e814648 fix: don't apply nil CallOption and ConnOpt 2019-01-07 01:47:28 +08:00
Sergey Mudrik
549eb959f0 Replaced log.Logger parameter by interface (#20) 2018-08-31 09:05:25 -07:00
Sergey Mudrik
073230af28 Use the last stable Go on Travis CI (#21) 2018-08-31 09:04:50 -07:00
Sergey Mudrik
aa573bdc2a Added link to the godoc reference (#19) 2018-08-22 01:37:14 -07:00
Keegan Carruthers-Smith
a3d86c792f allow multiple OnRecv and OnSend 2018-05-01 19:02:17 +01:00
Keegan Carruthers-Smith
2ed59d3304
remove content type from vscode object codec (#18) 2018-03-29 15:25:20 +02:00
Stephen Gutekanst
dbf20885e7
Merge pull request #17 from sourcegraph/sg/suppress
add support for suppressing ErrClosed in HandlerWithError logs
2018-02-12 18:08:19 -07:00
Stephen Gutekanst
c9e82539c3 add support for suppressing ErrClosed in HandlerWithError logs 2018-02-09 17:25:59 -07:00
Ondřej Kupka
c6c7b9aa99 Response: Add omitempty tag for Result (#14)
The 'result' key MUST be unset according when the error key is set.
This is not what is happening right now. When the error is set,
"result":null is returned in the response payload. This patch is fixing
the issue by adding omitempty for the result field.
2017-08-02 20:50:46 +02:00
Keegan Carruthers-Smith
b02337b177 typo in AsyncHandler docstring 2017-02-21 17:51:53 +02:00
Keegan Carruthers-Smith
3a7c446248 Handle is blocking (#12)
NOTE: This is a breaking change to the expected contract of Handler. Please update your implementation to use AsyncHandler if needs be.

We have strict ordering requirements of how we handle FileSystem requests in
LSP. As such relying on the ordering the goroutine scheduler runs requests in
leads to potential out of order mutations to the FS. As such we update the
jsonrpc2 implementation to by default block until Handle returns (note it can
still respond to the request at a later stage). For more simple use cases we
provide the AsyncHandler which will work like the previous implementation.

* Ensure handle is blocking
2017-02-21 14:25:50 +02:00
Keegan Carruthers-Smith
277d2464cf ci: disable testing tip (#11)
It is failing the tests. This may actually be an underlying issue in the tests,
but not a big deal to fix now.
2017-02-20 04:55:33 -08:00