[netstack2] Fix endpoint double close bug and handle receiving TCP RST immediately

This change addresses a bug which leads to an endpoint (that can have references
to it by multiple socketImpls) may attempt to cleanup its resources multiple
times, resulting in a panic when we attempt to close a closed go channel.

The bug:
1) Accept is called on a listening socket.
2) Create an endpoint and a socketImpl referencing the endpoint, return the
   socketImpl.
3) Receive a TCP RST which closes the endpoint (it only had a ref count of 1
   which drops to 0 so it gets closed).
4) Clone the socketImpl which results in a new socketImpl but with a reference
   to the original endpoint (the ref count of the endpoint increases to 1).
5) Close the new socketImpl (which closes the endpoint again since the ref count
   drops back to 0).

Step 5 is where the bug occurs (before this change, the cleanup would would be
done twice).

This change also addresses another bug where a TCP connection may be closed
immediately after being accepted (receiving a TCP RST on an endpoint that was
just Accepted but not yet returned to the caller of Accept).

Test: Test that closing an endpoint twice will not result in a panic.

Bug: 37475

Change-Id: Ie19f45cb2d864ee13f64ae1685eaa205a3802a46
7 files changed
tree: a410ed2d2981ce0bdf5ce35b13c50b88e9e09b56
  1. boards/
  2. build/
  3. bundles/
  4. docs/
  5. examples/
  6. garnet/
  7. peridot/
  8. products/
  9. scripts/
  10. sdk/
  11. src/
  12. third_party/
  13. tools/
  14. zircon/
  15. .clang-format
  16. .clang-tidy
  17. .dir-locals.el
  18. .gitattributes
  19. .gitignore
  20. .gn
  21. .style.yapf
  22. AUTHORS
  23. BUILD.gn
  24. CODE_OF_CONDUCT.md
  25. CONTRIBUTING.md
  26. LICENSE
  27. OWNERS
  28. PATENTS
  29. README.md
  30. rustfmt.toml
README.md

Fuchsia

Pink + Purple == Fuchsia (a new operating system)

What is Fuchsia?

Fuchsia is a modular, capability-based operating system. Fuchsia runs on modern 64-bit Intel and ARM processors.

Fuchsia is an open source project with a code of conduct that we expect everyone who interacts with the project to respect.

How can I build and run Fuchsia?

See Getting Started.

Where can I learn more about Fuchsia?

See fuchsia.dev.