Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fixed-length paths in memifproxy #285

Closed
d-uzlov opened this issue Jun 23, 2021 · 9 comments
Closed

Use fixed-length paths in memifproxy #285

d-uzlov opened this issue Jun 23, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@d-uzlov
Copy link
Contributor

d-uzlov commented Jun 23, 2021

In memifproxy we create unix sockets with path containing connection id.

func listenSocketFilename(conn *networkservice.Connection) string {
return filepath.Join(os.TempDir(), "memifproxy", conn.GetId(), "memif.socket")
}

This is an easy way to ensure that every connection has its own unique socket, but it has drawbacks.
Unix sockets are limited in length. On linux the limit is 108.
Connection IDs are not limited in length, and paths that contain them can easily exceed this limit. Related issue: networkservicemesh/deployments-k8s#1826
To ensure reliable behavior we must not use any variable length strings when defining paths.
We have several possible solutions for this:

Solution 1

Use relative paths.
I don't think is an appropriate solution because in order to use relative path to a file in a certain directory we would need to change current working directory, and this is basically incompatible with multithreading.

Solution 2

Keep [connection id -> uuid] map in memifproxy, and use these uuids for socket paths.

Solution 3

Use short symlinks to sockets with potentially long paths.
This is basically identical to second solution, because we would still need to keep mapping from connection id to its symlink, so I believe it's overly complicated without any real benefits.

Conclusion

I think that the only suitable solution here is the second: use mapped uuids for socket paths.
It would also be pretty easy to implement.

There is still another unknown-length part of the path: os.TempDir(). Temp directory is usually just /tmp by default, but it is not guaranteed. For example, it seems like on MacOS default temp dir is relatively long (48 symbols). And, of course, users can set temp dir to be whatever they want.
We can probably say that very long temp dir path is just an invalid configuration for a program that uses memifproxy.

@denis-tingaikin denis-tingaikin added the enhancement New feature or request label Jun 23, 2021
@denis-tingaikin
Copy link
Member

Solution2 looks good to me.

@edwarnicke Can you also have a look at the issue and share your thoughts?

@edwarnicke
Copy link
Member

Keep [connection id -> uuid] map in memifproxy, and use these uuids for socket paths.

Which is state we will lose when we heal :(

Use short symlinks to sockets with potentially long paths.
symlinks will break grpcfd in terms of passing them between Pods

Use relative paths.

You are correct about the issues for this within NSM. However, VPP's api runs in a single worker thread. It may very well be doable to upstream code to VPP that does the relative path trick.

@edwarnicke
Copy link
Member

In the immediate term: why are we ever setting the connection id manually in any of our things like cmd-nsc ?

@denis-tingaikin
Copy link
Member

denis-tingaikin commented Jun 23, 2021

Which is the state we will lose when we heal :(

Basically, memif chain element is using in next places

  1. client
  2. forwarder
  3. endpoint

Let's consider death cases:

  1. client died -- nothing to heal
  2. forwarder/endpoint died -- we need to re-create memif folder with the socket on the forwarder/endpoint side.

it seems solution 2 can be used.

Did I miss something?

UPD: we also could store the map connId to sockerDir on the disk.

@edwarnicke
Copy link
Member

In the immediate term: why are we ever setting the connection id manually in any of our things like cmd-nsc ?

@denis-tingaikin
Copy link
Member

denis-tingaikin commented Jun 24, 2021

In the immediate term: why are we ever setting the connection id manually in any of our things like cmd-nsc ?

Note: we are setting id manually because we want to not see issues on NSC restarting.

And it is not manually, we are using the unique name of Pod.

See at networkservicemesh/cmd-nsc-vpp#180

@edwarnicke
Copy link
Member

@denis-tingaikin What issues would we see on NSC restarting if we didn't manually set its connection ID?

@denis-tingaikin
Copy link
Member

denis-tingaikin commented Jun 24, 2021

@edwarnicke

  1. resources leaking on forwarder, manager, and etc. Resouces will be not disposed of until token expiration. This problem may be critical for restarting clients. (Imagine a ton of interfaces on the forwarder side that produces by the client restarting...)
  2. Client may lose selected endpoint on restarting.
  3. In the case of external clients we need also to identify the sidecar client as the init container client.

@NikitaSkrynnik
Copy link
Contributor

NikitaSkrynnik commented Mar 25, 2022

Can't reproduce the problem. MemifProxy client has been deleted in this #470. MemifProxy server doesn't have this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants