Commit Graph
23 Commits
Author SHA1 Message Date
Hamza El-Saawy 3c9576c934 Update go1.21 and CI (#315)
* Update to go 1.21

Use `atomic.Bool` stdlib instead of including our own.

Include `tools\mkwinsyscall` updates from go-winio/283 to switch to
`syscallN`.
Note: removed `// TODO` about `print`/`ln`, since the latter adds spaces
between args when printing, which is undesired.

Also update CI to run steps on windows-2022 instead of windows-2019,
similar to our hcsshim CI.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* PR: simplify type checking

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

---------

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2024-04-09 16:07:04 -04:00
Hamza El-Saawy 9f0d5dc7d2 Switch from sycall to windows (#295)
Where ever possible, use `golang.org/x/sys/windows` instead of `syscall`
(which has been deprecated since go1.11).

Using `windows.LocalFree` requires using `unsafe.Pointer`, which ensures
that the Go garbage collector does not try to free memory pre-maturely
if it was previously declared as a pointer.

Since `syscall.Handle` is part of API for `vhd` package, it was left
unchanged.

For security descriptor functions, switch to using
`windows.SECURITY_DESCRIPTOR` to avoid unnecessary byte manipulation and
panics due to missing input validation and error checking.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2023-08-07 14:06:05 -04:00
David Golub b29bbd58a6 Add support for flushing and disconnecting named pipes (#292)
* Add support for disconnecting pipes

Signed-off-by: David Golub <david.golub@mongodb.com>

* Expose Flush

Signed-off-by: David Golub <david.golub@mongodb.com>

* Add test

Signed-off-by: David Golub <david.golub@mongodb.com>

* Fix lint errors

Signed-off-by: David Golub <david.golub@mongodb.com>

---------

Signed-off-by: David Golub <david.golub@mongodb.com>
2023-07-24 15:25:19 -04:00
Hamza El-Saawy 19a9f656e1 Update tests; run fuzzing (#294)
Run fuzzing tests in CI.

Use race detector when running tests.

Add missing `t.Helper()` calls.

Update test helpers in `pkg/bindfilter` to use `RtlGetNtVersionNumbers`
instead of reading registry, and skip tests if not running as admin.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2023-07-21 18:06:41 -04:00
Hamza El-Saawy e268c11e27 Add lint and go generate steps to CI (#254)
* Add lint and go generate stages to CI

Add CI step to verify `go generate` was run on repo.
Add linter stage to CI along with linter config file,
`.golangci.yml`.
Will likely prefer revive over static-check.

Updated README Contributing section on linting requirements.

Added sequence ordering to make sure lint and go generate stages run
before tests and build.
This way, build and tests are not run on code that could potentially:

    1. not build due to `gofmt` issues;
    2. contain bugs;
    3. have to be re-submitted after issues are fixed; or
    4. contain outdated Win32 syscall or other auto-generated files.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* Fixed linter issues

Code changes to satisfy linters:

 - Ran `gofmt -s -w` on repo.
 - Broke up long lines.
 - When possible, changed names with incorrect initialism formatting
   - Added exceptions for exported variables.
 - Added exceptions for ALL_CAPS_WITH_UNDERSCORES code.
   - Switched to using `windows` or `syscall` definitions if possible;
     especially if some constants were unused.
 - Added `_ =` to satisfy error linter, and acknowledge that errors are
   being ignored.
 - Switched to using `errors.Is` and `As` in places, elsewhere added
   exceptions if error value was known to be `syscall.Errno`.
 - Removed bare returns.
 - Prevented variables from being overshadowed in certain places
   (ignoring cases of overshadowing `err`).
 - Renamed variables and functions (eg, `len`, `eventMetadata.bytes`) to
   prevent shadowing pre-built functions and imported pacakges.
 - Removed unused method receivers.
 - Added exceptions to certain unused (unexported) constants and
   functions.
   - Deleted unused `once` from `pkg/etw.providerMap`.
 - Renamed `noop.go` files to `main_other.go` or `doc.go`, to better fit
   style recommendations.
 - Added exceptions for non-secure use of SHA1 and weak crypto
   libraries.
 - Replaced `ioutil` with `io` and `os` (and `t.TempDir` in tests).
 - Added fully exhaustive checks for `switch` statements in `pkg/etw`.
 - Defined constant strings for `tools/mkwinsyscall`.
 - Removed unnecessary conversions.
 - Made sure `context.Cancel` was called.

Additionally, added `//go:build windows" constraints on files with
unexported code, since linter will complain about unused code on
non-Windows platforms.

Added a stub `main() {}` for `mkwinsyscall` for non-Windows builds, just in
case `//go:generate` directives are added to OS-agnostic files.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* PR: spelling, constants, fuzzing

Moved HVSocket fuzzing tests to separate file with go 1.18 build
constraint.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2022-08-23 15:05:05 -04:00
Danny Canter 1e35b45f32 Bump go version to 1.17 in go.mod/CI (#230)
1.13 is sufficiently old at this point and net.ErrClosed from 1.16 will be nice
to use.

This change additionally runs go fmt to bring in the new 1.17 build tag syntax
and builds the binaries in our CI with 1.17+.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
2022-04-05 15:56:47 -07:00
Thomas d4c02ad896 Add missing build constraints 2021-02-10 23:54:19 +00:00
John Howard 84b4ab48a5 Merge pull request #125 from jstarks/listenpipe
pipe: Fix ListenPipe/DialPipe race
2019-04-08 10:36:21 -07:00
John Starks bd71ef0e5d pipe: Fix ListenPipe/DialPipe race
ListenPipe can fail if there is a concurrent DialPipe because there is a
race window where DialPipe can connect to the initial server named pipe
before it is connected to and closed by ListenPipe.

To fix this, use the lower-level NT API for creating the server pipe,
since this API allows for specifying that a server pipe should initially
be in the disconnected state instead of the listening state. This allows
us to avoid the race condition by creating the pipe in the correct state
initially, so there is no longer a need to create a dummy client
connection.
2019-04-08 10:08:23 -07:00
sime1 693f74258b context timeout test 2019-03-26 18:36:36 +01:00
Simeone 665a579a64 test context cancel error type 2019-03-26 10:10:46 +01:00
Simeone 5fdbdcc2ae add DialPipeContext 2019-03-26 09:43:43 +01:00
John Starks 3eabd1969d Clean up message mode pipe handling, add test 2018-06-25 09:31:55 -07:00
John Starks ae842e48e0 pipe: Resolve race between close and connect
This change resolves the issue where Accept() returns ERROR_NO_DATA
because the client closes the connection immediately. It resolves
the race by ignoring that particular connection and waiting on a
new one.
2018-01-09 13:28:13 -08:00
Darren Stahl 3d52dc4a97 Test bug: Fix server connections not closing in TestEchoWithMessaging
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-08-04 10:24:26 -07:00
Darren Stahl 2a0317319a Adding failing tests for deadlines on pending IO
Signed-off-by: Darren Stahl <darst@microsoft.com>
2017-05-05 14:53:42 -07:00
Simon Ferquel 203d18a858 Introduces a test that does an echo using message mode named pipes
This exhibit a deadlock we see sometimes when using docker cli connected
to a daemon through a named pipe with some data in the input stream (ie:
`echo "hello" | docker run ... `)

The problem seems to be that the EOF 0-length message is collapsed with
the previous message, if the buffer associated with the named pipe is
not previously flushed

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
2017-03-17 16:43:53 +01:00
John Starks 36f4e701c4 Add support for CloseWrite() to pipes
This change adds support for message mode pipes and uses them to support
CloseWrite() to better match TCP and UNIX sockets. Message mode pipes
support writing and (optionally) reading data in message-sized chunks.
This is useful for us because when in this mode a zero-sized message can
be read. We use this zero-sized message to signal that no more writes will
arrive. This is not standard practice in Windows, but it is a reasonable
compromise.
2016-03-15 11:58:02 -07:00
John Starks 0c1e4a09ec Add tests that check for EOF on pipe close 2016-03-14 16:33:35 -07:00
John Starks 99eef7be8d Ensure DialPipe times eventually by default
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 14:00:21 -08:00
John Starks 3191792462 Fix errors to better match net package
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 13:47:08 -08:00
John Starks b0d265e6c2 Ensure win32PipeListener.Close() correctly aborts Listen() calls
Signed-off-by: John Starks <jostarks@microsoft.com>
2016-01-31 13:46:55 -08:00
John Starks f001f808a9 Add file and pipe Windows wrappers
This includes Reader, Writer, and Closer interfaces on top of
Windows file handles in a way that does not block the system thread
while the IO is outstanding.

This also includes net.Listener and net.Conn for named pipes.
2016-01-30 18:11:47 -08:00