Repository navigation
Do not unwrap on flow table limits - #347
Conversation
|
Fixes #346. This PR removes some of the lingering There's not really a great static limit we can apply here. This PR uses the I've verified that this panic is fixed with a new integration test. That creates a tiny flow-table of 1 entry, and then tries to send two outbound packets through the OPTE port. Here's the behavior of that integration test on On this PR branch, that test passes fine. One thing I'm not sure about is really whether this is the right solution. There are two aspects to this. First, we're sizing both the TCP and UFT flow tables to be the number of ports. But the UFT flow table will include non-TCP connections, suggesting we might want that to be larger. It seems overkill to make the table large enough to hold all possible protocols, though, so I don't know the right answer. The other aspect is the failure mode when a guest tries to open a connection and the table is exhausted. We just drop the packet. I don't think there's anything else we can reasonably do, but it still feels odd. For example, a guest might have 16k entries in their table. But from the perspective of the guest OS, there's no real reason that one couldn't open a socket on all 65K ports. With this fix, they'd just see some of those time out. Like I said, I'm not sure what else one can do, since we can't really inject an RST or something back into the guest without confusing the crap out of them. @rmustacc and @rcgoodfellow I'd love to hear if you have any thoughts on that. But the TL;DR is that this should address the panic itself. |
2e7df4c to
83cee54
Compare
- Add error type for handling TCP flow errors - Return new error variants rather than `String` from methods processing TCP flows. - Handle TCP flow errors, now just unexpected segments, in the port processing code. This is done by returning a new `ProcessError` variant. - Add `ProcessError::FlowTableFull`, which wraps attempts to add a new flow entry which fail because the table is full. This includes the table "kind", which for now is just a static string, and the current limit. - Add an integration test verifying that TCP packets are dropped when the flow table is full.
83cee54 to
94ad47a
Compare
|
Ah, I also just realized this may be alleviated by a solution to #315. It's possible there are not 8096 active connections, but there have been more than 8096 connections made at some point. We should certainly get rid of these unwraps, but we may want to revisit the choices of size made here (based on the VPC config). |
jmpesp
left a comment
There was a problem hiding this comment.
I tested this, and the host no longer panics in the same situation. ![]()
|
Thanks for addressing the panic! Was out Friday so just taking a look today. Reading through the issue a bit now, I'd propose a different approach: adding an entry to the flow tables should be infallible. We already expect flows to expire after some time (or just be removed explicitly in the case of TCP when the state machine gets to close/reset). If the table's full, we should just retire the earliest flow (*). Of course that still requires tweaking table size so we're not constantly ping-ponging flows in and out. (*) have to check but not sure if the current structure of the code allows easily determining earliest flows, in which case I'd say just clearing the table all together is not the worst short-term option. All flows are already currently hard-coded with a TTL of 60s today AFAIK. |
|
Thanks @luqmana. That approach seems plausible. I don't see a quick way to look up the flows in time order now, so we'd need to add a "secondary index" to In any case, I'm not what to make of this design. Talking out loud a bit, let's suppose we picked an arbitrary flow table limit, as we currently do, of N. All connections up to N would behave the same way, in that we'd set up a UFT and then keep hitting it as long as those are active. For connections made beyond N however, flows would start to behave less predictably. First, we'd have some initial setup time to find and remove the oldest flow and insert the new one. Second, there'd be some complicated interactions, where adding new connections would start to impact others. The impacted ones are "old," so that might be fine. It seems particularly hard to reason about in a guest that has a lot of active connections, such as a database server or load balancer. That might be an edge case though, I really don't know. |
|
I agree but there is already some amount of unpredictability given the slow-path (traverse layers), fast-path (lookup in UFT) design. But I think that's better than just dropping the packets. It's definitely something we can tweak with how long before we expire flows and how big of a table we use. But that's already where we're at today. Another not fully fleshed out idea is maybe just skip creating a table entry if it's full but otherwise deliver the packet as normal. Downside is subsequent packets will end up hitting slowpath but by then perhaps previous flows would've expired? |
|
That's fair about the existing design. I would imagine it's slow once, and then fast after that (assuming enough consistent activity to not expire the flow). You're definitely right though, some amount of this is already there. It's a good point that we'd degrade more gracefully if we drop old flows as new ones above the static limit come in. As this is currently implemented, those TCP connections would just be slow to establish until / unless other flows were expired based on time. It might be better to have it driven by time and guest activity. By "skip creating the table entry," you mean the UFT table? So that would mean the flow would always be layer-processed? That's an interesting idea. It's similar to the first proposal, except newer flows can't bump older ones out of the UFT. Those later flows would be slower but more predictable, IIUC. That sounds better that the FIFO-esque behavior of the UFT, given how sensitive TCP can be to small latency variations. I think I'm on board with one or both of your proposals, with a slight preference for the second (not adding a UFT entry if it's full, and using layer-processing instead). |
Right, at the point we'd be running into this we're already in the slow-path for that flow. Not returning an error/dropping the packet then would mean a subsequent packet would hit the slow-path again but hopefully by then we have space. In the slightly longer term we should probably start thinking of different workloads & usecases to start collecting perf data. We can add some probes/stats in this case to see how often we run into this situation and use that to better size the table. |
| pmeta: &PacketMeta, | ||
| pkt_len: u64, | ||
| ) -> result::Result<TcpState, String> { | ||
| ) -> result::Result<TcpState, ProcessError> { |
There was a problem hiding this comment.
I would use a separate error here so you don't need all the unreachable! cases for errors that don't apply. You can then add that as a variant to ProcessError if you want.
I've been thinking more about this. A lot of this is notes for myself, but it hopefully helps others. I was having some trouble squaring this with the ideas in RFD 21 and the current implementation in Nexus. In particular, we limit SNAT IP addresses to 16K ports. Let's suppose we follow this proposal, of "falling back" to layer-processing when a guest hits the size limit for a UFT table. I couldn't quite grok how our 16K limit is actually limiting anything though. As a concrete example, if we allow 16K + 1 connections, what port do we rewrite the outgoing packets with? We can't pick anything outside the range that OPTE's So it seemed like we'd need to drop something, say this new connection or the oldest. Both of those suck as a customer experience. There's nothing inherent in the VM that would appear to be limiting. The The think I'm doing here is conflating two distinct objects: the unified flow table, and the NAT pool. The former is really just to store the "compiled" set of rules applying to a particular flow, as an optimization avoiding iterating over each layer and action for every packet. The latter is the pool of IPs (always one right now) and ports that are available to the guest for use. There are two flavors of this: These are different things. The WIP I have here makes them the same size, so that every possible connection a guest can make is equally snappy. But they are still different things, and different limits and policies may apply to them. One thing that's confusing here is that, the current All of this is to say that (1) the proposal of less efficient processing is fine, (2) limiting the size of the pool to the number of connections the guest can make is also fine (I think?), but unnecessary. If the guest is in fact limited, because they've an SNAT IP with 16K ports only, then the packets will already be dropped because the |
|
@bnaecker can we merge this? It fixes a crash we are encountering in system-level testing. Perhaps with some follow on issues for remaining items. |
|
@luqmana It looks like the fix here is blocking some other work, so I'd like to merge this. I'll file a new issue to track moving towards what we discussed: new flows are either always layer-processed; displace the oldest flow; or result in entirely clearing the UFT when it's full. |
Lag between when #347 was created vs merged means some tests need to be fixed.
Stringfrom methods processing TCP flows.ProcessErrorvariant.ProcessError::FlowTableFull, which wraps attempts to add a new flow entry which fail because the table is full. This includes the table "kind", which for now is just a static string, and the current limit.