Commit Graph

83 Commits

Author SHA1 Message Date
Canelo Hill ccd407c1f7 Update for deprecated ioutil package 2024-06-18 14:48:58 -06:00
apoorvajagtap ce903f6d1d Reverts to v1.5.0
This commit reverts the changes back till 8983b96324.
And inherits the README.md changes of 931041c5ee
Relates to:
- https://github.com/gorilla/websocket/issues/880#issuecomment-2081189055
2024-06-13 23:18:03 -04:00
apoorvajagtap 1bddf2e0db bumps go version & removes deprecated module usage 2024-05-01 18:51:54 +05:30
apoorvajagtap b2c246b2ec Revert " Update go version & add verification/testing tools (#840)"
This reverts commit 666c197fc9.
2024-05-01 18:51:54 +05:30
apoorvajagtap 09a6bab466 removing error handling while closing connections 2024-04-01 22:33:57 -04:00
Martin Greenwald b2a86a1744 Do not timeout when WriteControl deadline is zero
A zero value for the Conn.WriteControl deadline specifies no timeout,
but the feature was implemented as a very long timeout (1000 hours).
This PR updates the code to use no timeout when the deadline is zero.

See the discussion in #895 for more details.
2024-03-05 22:56:06 -05:00
Rumen Nikiforov 695e9095ce
Remove hideTempErr to allow downstream users to check for errors like net.ErrClosed (#894)
Since this change
https://github.com/gorilla/websocket/pull/840/files#diff-4f427d2b022907c552328e63f137561f6de92396d7a6e8f6c2ea1bcf0db52654L190-R197
we can no longer determinate if the errors coming from ReadMessage() are
net.ErrClosed for example
Hardcoding the error message is not great option because it may vary
from OS to OS and system locale
2024-02-15 12:59:16 +10:00
rfyiamcool 0cfb2cafd0 feat: format message type
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-02-13 23:01:06 -05:00
rfyiamcool d15aba1e61 perf: reduce timer in write_control
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
2024-01-22 22:58:11 -05:00
Kenjiro Nakayama cf50a3efbb Revert "Print log message"
This reverts commit 6db907caed.
2024-01-21 23:02:08 -05:00
Kenjiro Nakayama 7d5b8cce7e Print log message 2024-01-21 23:02:08 -05:00
Kenjiro Nakayama 4965080703 Do not return error in SetCloseHandler 2024-01-21 23:02:08 -05:00
Kenjiro Nakayama 9a2140519a Do not handle network error in SetCloseHandler()
The 666c197 added an error handling in `SetCloseHandler()` and peer
stops getting `CloseError` when network issue like `write: broken
pipe` happens because the close handle returns the error.

Hence this patch changes to skip network error handling.
2024-01-21 23:02:08 -05:00
Brendan Creane dcea2f088c Remove noisy printf in NextReader() 2023-12-10 23:08:54 -05:00
Henrik Hautakoski 6f5d2139f4
conn.go: default close handler should not return ErrCloseSent. (#865)
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [ ] Refactor
- [ ] Feature
- [x] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Go Version Update
- [ ] Dependency Update

## Description

Noticed a change in default close handler from 1.5.0 to 1.5.1

1.5.1 Now returns the error from `WriteControl` with `CloseMessage`
type. However this results in ErrCloseSent returned if the connection
initiated the close handshake. This is normally correct as the
connection should not be able to write after a close handshake is
initiated, except when calling the close handler. in that case nil
should be returned so that `advanceFrame()` can return the actual close
message.

## Related Tickets & Documents

## Added/updated tests?

- [x] Yes
- [ ] No, and this is why: _please replace this line with details on why
tests
      have not been included_
- [ ] I need help with writing tests

## Run verifications and test

- [ ] `make verify` is passing (fails with `GO-2023-2186 Incorrect
detection of reserved device names on Windows in path/filepath` that is
unrelated to this change)
- [x] `make test` is passing

Co-authored-by: Corey Daley <cdaley@redhat.com>
2023-11-12 19:54:23 -05:00
Corey Daley 666c197fc9
Update go version & add verification/testing tools (#840)
Fixes #

**Summary of Changes**

1.
2. 
3.

> PS: Make sure your PR includes/updates tests! If you need help with
this part, just ask!
2023-08-27 01:31:45 +05:30
JWSong 78cf1bc733
Changed the method name UnderlyingConn to NetConn to align the methods names with Go 1.18 standard library (#773) 2022-04-17 06:01:17 -07:00
Gary Burd 4fad403619
Remove support for Go 1.8 2022-01-02 15:53:55 -08:00
Gary Burd f0643a3a18
Improve protocol error messages
To aid protocol error debugging, report all errors found in the first two bytes of a message header.
2022-01-02 12:16:08 -08:00
Maxim Fominykh d11356942f
Duration order consistency when multiplying number by time unit (#570) 2020-03-19 07:01:23 -07:00
ferhat elmas 015e196e21
Use empty struct to protect writing (#566)
Using empty struct for signaling is more idiomatic
compared to booleans because users might wonder
what happens on false or true. Empty struct removes
this problem.

There is also a side benefit of occupying less memory
but it should be negligible in this case.
2020-03-19 06:52:00 -07:00
Matt Silverlock 5b740c2926
Read Limit Fix (#537)
This fix addresses a potential denial-of-service (DoS) vector that can cause an integer overflow in the presence of malicious WebSocket frames.

The fix adds additional checks against the remaining bytes on a connection, as well as a test to prevent regression.

Credit to Max Justicz (https://justi.cz/) for discovering and reporting this, as well as providing a robust PoC and review.

* build: go.mod to go1.12
* bugfix: fix DoS vector caused by readLimit bypass
* test: update TestReadLimit sub-test
* bugfix: payload length 127 should read bytes as uint64
* bugfix: defend against readLength overflows
2019-08-24 18:17:28 -07:00
Tariq Ibrahim 6a67f44b69 remove redundant err!=nil check in conn.go Close method (#505) 2019-04-26 23:02:11 -05:00
kanozec 483fb8d7c3 Add "in bytes" to sizes in documentation 2018-10-30 07:45:53 -07:00
Steven Scott 3130e8d3f1 Return write buffer to pool on write error (#427)
Fix bug where connection did not return the write buffer to the pool
after a write error. Add test for the same.

Rename messsageWriter.fatal method to endMessage and consolidate all
message cleanup code there. This ensures that the buffer is returned to
pool on all code paths.

Rename Conn.prepMessage to beginMessage for symmetry with endMessage.
Move some duplicated code at calls to prepMessage to beginMessage.

Bonus improvement: Adjust message and buffer size in TestWriteBufferPool
to test that pool works with fragmented messages.
2018-09-24 16:26:12 -07:00
Steven Scott b378caee5b Add write buffer pooling
Add WriteBufferPool to Dialer and Upgrader. This field specifies a pool
to use for write operations on a connection.  Use of the pool can reduce
memory use when there is a modest write volume over a large number of
connections.

Use larger of hijacked buffer and buffer allocated for connection (if
any) as buffer for building handshake response. This decreases possible
allocations when building the handshake response.

Modify bufio reuse test to call Upgrade instead of the internal
newConnBRW. Move the test from conn_test.go to server_test.go because
it's a serer test.

Update newConn and newConnBRW:

- Move the bufio "hacks" from newConnBRW to separate functions and call
these functions directly from Upgrade.
- Rename newConn to newTestConn and move to conn_test.go. Shorten
argument list to common use case.
- Rename newConnBRW to newConn.
- Add pool code to newConn.
2018-08-22 14:11:59 -07:00
Adam Shannon 5fb94172f4 drop Go versions prior to 1.7 in CI
* drop Go versions prior to 1.7 in CI

* consolidate conn*.go files after dropping old Go support
2018-08-22 14:10:37 -07:00
Gary Burd eb92580837
Use net.Buffers to write multiple slices to connection
Closes #346.
2018-03-06 10:15:48 -08:00
Gary Burd 4ac909741d
Improve control message handler doc
Fixes #338
2018-01-31 17:52:56 -08:00
Gary Burd 292fd08b25
Replace "frame" with "message" in documentation
The documentation sometimes used the term "frame" when referring to
single frame control messages.  Use the term "message" for consistency
in the documentation and to hide a detail that most application
programmers do not need to know about.
2018-01-10 06:15:25 -08:00
Gary Burd d965e9adc6
Handle no status in FormatCloseMessage
Return empty message for CloseNoStatusReceived. This status indicates
that the message is empty, so make it so. Because it's illegal to send
CloseNoStatusReceived, this change should not break a correct
application.
2017-12-28 07:29:59 -08:00
Gary Burd 23059f2957 Update with gofmt on tip
The changes are compatible with older versions of gofmt.
2017-11-23 00:11:29 -08:00
Gary Burd f918560c4c Improve NextWriter documentation 2017-10-10 09:16:43 -07:00
xPushkin c908dc801c Typo fix
Just a small typo fix.
2017-10-07 13:56:17 -07:00
Gary Burd b258b4fadb Use bufio.Writer returned from hijack in upgrade
Reuse the buffer backing the bufio.Writer returned from hijack if that
buffer is large enough to be generally useful and
Upgrader.WriteBufferSize == 0.

Update the logic for reusing bufio.Reader returned from hijack to match
the logic for bufio.Reader:  The buffer backing the reader must be
sufficiently large to be generally useful and Upgrader.ReadBufferSize ==
0.

Improve the documentation for ReadBufferSize and WriterBufferSize in
Dialer and Upgrader.
2017-03-02 14:46:13 -08:00
Gary Burd 4873052237 Fix formatting. 2017-03-01 09:42:05 -08:00
Gary Burd 286b5c9371 Use bufio.Reader returned from hijack in upgrade
Use the bufio.Reader returned from hijack if the reader's buffer size is
equal to the buffer size specified in Upgrader.ReadBufferSize.
2017-03-01 09:36:54 -08:00
Gary Burd 804cb600d0 Prepared Messages (#211) 2017-02-14 09:41:18 -08:00
Gary Burd 2257eda00b Fix compile error on Go < 1.6 2017-01-19 11:27:08 -08:00
Gary Burd b0dc45572b Change default and add API for compression level
Change the default compression level to 1. This level is faster and uses
less memory.

Add Conn.SetCompressionLevel API to allow applications to tune
compression on a per message basis.
2017-01-19 11:00:23 -08:00
Gary Burd bb547c6c5c Improve SetXHandler documentation 2017-01-15 13:09:21 -08:00
Gary Burd adf16b3178 Add safe maskBytes
Fixes #200.
2016-12-31 20:13:41 -08:00
Gary Burd 6c51b25bc8 Compression improvements
- Remove unnecessary error return from compressNoContextTakeover.
- Simplify use of sync.Pool.
- Fix formatting in compression documentation.
2016-12-27 17:05:16 -05:00
Cyrus Katrak 2db2f66488 pool flate readers 2016-12-19 07:28:05 -08:00
Gary Burd 0868951cdb Improve WriteMessage fast path
Restructure to avoid messageWriter allocation.
2016-12-07 16:21:58 -08:00
Gary Burd 9fbf129ff2 Add Conn.[Set]CloseHandler 2016-11-02 13:04:59 -07:00
Gary Burd 80a0029a65 Improve write error handling
- Do not fail NextWriter when close of previous writer fails.
- Replace closeSent field with mutex protected writeErr. Set writeErr on
  any error writing to underlying network connection. Check and return
  writeErr before attempting to write to network connection. Check
  writeErr in NextWriter so application can detect failed connection
  before attempting to write.
- Do not close underlying network connection on error.
- Move message writing state and method flushFrame from Conn to
  messageWriter. This makes error code paths (and the code in general)
  easier to understand.
- Add messageWriter field err to latch errors in messageWriter.

Bonus: Improve test coverage.
2016-11-02 09:59:14 -07:00
Gary Burd 77f110791c Improve mask performance 2016-10-21 11:11:39 -07:00
Cyrus Katrak c09b72d2ee per message compression; only no context modes 2016-10-14 12:08:39 -07:00
Gary Burd a87eae1d6f Add hooks to support RFC 7692 (per-message compression extension)
Add newCompressionWriter and newDecompressionReader fields to Conn. When
not nil, these functions are used to create a compression/decompression
wrapper around an underlying message writer/reader.

Add code to set and check for RSV1 frame header bit.

Add functions compressNoContextTakeover and decompressNoContextTakeover
for creating no context takeover wrappers around an underlying message
writer/reader.

Work remaining:

- Add fields to Dialer and Upgrader for specifying compression options.
- Add compression negotiation to Dialer and Upgrader.
- Add function to enable/disable write compression:

    // EnableWriteCompression enables and disables write compression of
    // subsequent text and binary messages. This function is a noop if
    // compression was not negotiated with the peer.
    func (c *Conn) EnableWriteCompression(enable bool) {
            c.enableWriteCompression = enable
    }
2016-06-29 17:03:55 -07:00