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

[Filebeat] cel input - deeply nested 'state' after HTTP error #33992

Closed
andrewkroh opened this issue Dec 8, 2022 · 2 comments · Fixed by #33996
Closed

[Filebeat] cel input - deeply nested 'state' after HTTP error #33992

andrewkroh opened this issue Dec 8, 2022 · 2 comments · Fixed by #33996
Labels

Comments

@andrewkroh
Copy link
Member

When an HTTP error occurs something bad happens.

  1. The state value becomes deeply nested (e.g. state: {state: {state: {state: ...} } }). See the log message below.
  2. This happens in a very short matter of time. Within a few milliseconds it has sent 100+ requests to the server. How can I prevent myself from DoSing my server if it returns some unexpected response?

Version: filebeat version 8.7.0 (arm64), libbeat 8.7.0 [0c77112 built 2022-12-08 04:13:10 +0000 UTC]

Reproduction

package main

import (
	"log"
	"net/http"
)

func main() {
	log.Fatal(http.ListenAndServe("localhost:9888", nil))
}
---

filebeat.inputs:
  - type: cel
    interval: 1m
    resource.url: http://localhost:9888

    resource:
      retry:
        min_wait: 10s
        max_wait: 120s

    program: |
      bytes(get(state.url).Body).as(body, {
        "events": [body.decode_json()]
      })


output.console.pretty: true

Logs

{
  "log.level": "debug",
  "@timestamp": "2022-12-07T23:13:42.101-0500",
  "log.logger": "input.cel",
  "log.origin": {
    "file.name": "cel/input.go",
    "file.line": 198
  },
  "message": "request state",
  "service.name": "filebeat",
  "id": " 155307A9CE29697",
  "input_source": "http://localhost:9888",
  "input_url": "http://localhost:9888",
  "cel": {
    "state": {
      "cursor": null,
      "state": {
        "cursor": null,
        "state": {
          "cursor": null,
          "state": {
            "cursor": null,
            "state": {
              "cursor": null,
              "state": {
                "cursor": null,
                "state": {
                  "cursor": null,
                  "state": {
                    "cursor": null,
                    "state": {
                      "cursor": null,
                      "state": {
                        "cursor": null,
                        "state": {
                          "cursor": null,
                          "state": {
                            "cursor": null,
                            "state": {
                              "cursor": null,
                              "state": {
                                "cursor": null,
                                "state": {
                                  "cursor": null,
                                  "state": {
                                    "cursor": null,
                                    "state": {
                                      "cursor": null,
                                      "state": {
                                        "cursor": null,
                                        "state": {
                                          "cursor": null,
                                          "state": {
                                            "cursor": null,
                                            "state": {
                                              "cursor": null,
                                              "state": {
                                                "cursor": null,
                                                "state": {
                                                  "cursor": null,
                                                  "state": {
                                                    "cursor": null,
                                                    "state": {
                                                      "cursor": null,
                                                      "state": {
                                                        "cursor": null,
                                                        "state": {
                                                          "cursor": null,
                                                          "state": {
                                                            "cursor": null,
                                                            "state": {
                                                              "cursor": null,
                                                              "state": {
                                                                "cursor": null,
                                                                "state": {
                                                                  "cursor": null,
                                                                  "state": {
                                                                    "cursor": null,
                                                                    "state": {
                                                                      "cursor": null,
                                                                      "state": {
                                                                        "cursor": null,
                                                                        "state": {
                                                                          "cursor": null,
                                                                          "state": {
                                                                            "cursor": null,
                                                                            "state": {
                                                                              "cursor": null,
                                                                              "state": {
                                                                                "cursor": null,
                                                                                "state": {
                                                                                  "cursor": null,
                                                                                  "state": {
                                                                                    "cursor": null,
                                                                                    "state": {
                                                                                      "cursor": null,
                                                                                      "state": {
                                                                                        "cursor": null,
                                                                                        "state": {
                                                                                          "cursor": null,
                                                                                          "state": {
                                                                                            "cursor": null,
                                                                                            "state": {
                                                                                              "cursor": null,
                                                                                              "state": {
                                                                                                "cursor": null,
                                                                                                "state": {
                                                                                                  "cursor": null,
                                                                                                  "state": {
                                                                                                    "cursor": null,
                                                                                                    "state": {
                                                                                                      "cursor": null,
                                                                                                      "state": {
                                                                                                        "cursor": null,
                                                                                                        "state": {
                                                                                                          "cursor": null,
                                                                                                          "state": {
                                                                                                            "cursor": null,
                                                                                                            "state": {
                                                                                                              "cursor": null,
                                                                                                              "state": {
                                                                                                                "cursor": null,
                                                                                                                "state": {
                                                                                                                  "cursor": null,
                                                                                                                  "state": {
                                                                                                                    "cursor": null,
                                                                                                                    "state": {
                                                                                                                      "cursor": null,
                                                                                                                      "state": {
                                                                                                                        "cursor": null,
                                                                                                                        "state": {
                                                                                                                          "cursor": null,
                                                                                                                          "state": {
                                                                                                                            "cursor": null,
                                                                                                                            "state": {
                                                                                                                              "cursor": null,
                                                                                                                              "state": {
                                                                                                                                "cursor": null,
                                                                                                                                "state": {
                                                                                                                                  "cursor": null,
                                                                                                                                  "state": {
                                                                                                                                    "cursor": null,
                                                                                                                                    "state": {
                                                                                                                                      "cursor": null,
                                                                                                                                      "state": {
                                                                                                                                        "cursor": null,
                                                                                                                                        "state": {
                                                                                                                                          "cursor": null,
                                                                                                                                          "state": {
                                                                                                                                            "cursor": null,
                                                                                                                                            "state": {
                                                                                                                                              "cursor": null,
                                                                                                                                              "state": {
                                                                                                                                                "cursor": null,
                                                                                                                                                "state": {
                                                                                                                                                  "cursor": null,
                                                                                                                                                  "state": {
                                                                                                                                                    "cursor": null,
                                                                                                                                                    "state": {
                                                                                                                                                      "cursor": null,
                                                                                                                                                      "state": {
                                                                                                                                                        "cursor": null,
                                                                                                                                                        "state": {
                                                                                                                                                          "cursor": null,
                                                                                                                                                          "state": {
                                                                                                                                                            "cursor": null,
                                                                                                                                                            "state": {
                                                                                                                                                              "cursor": null,
                                                                                                                                                              "state": {
                                                                                                                                                                "cursor": null,
                                                                                                                                                                "state": {
                                                                                                                                                                  "cursor": null,
                                                                                                                                                                  "state": {
                                                                                                                                                                    "cursor": null,
                                                                                                                                                                    "state": {
                                                                                                                                                                      "cursor": null,
                                                                                                                                                                      "state": {
                                                                                                                                                                        "cursor": null,
                                                                                                                                                                        "state": {
                                                                                                                                                                          "cursor": null,
                                                                                                                                                                          "state": {
                                                                                                                                                                            "cursor": null,
                                                                                                                                                                            "state": {
                                                                                                                                                                              "cursor": null,
                                                                                                                                                                              "state": {
                                                                                                                                                                                "cursor": null,
                                                                                                                                                                                "state": {
                                                                                                                                                                                  "cursor": null,
                                                                                                                                                                                  "state": {
                                                                                                                                                                                    "cursor": null,
                                                                                                                                                                                    "state": {
                                                                                                                                                                                      "cursor": null,
                                                                                                                                                                                      "state": {
                                                                                                                                                                                        "cursor": null,
                                                                                                                                                                                        "state": {
                                                                                                                                                                                          "cursor": null,
                                                                                                                                                                                          "state": {
                                                                                                                                                                                            "cursor": null,
                                                                                                                                                                                            "state": {
                                                                                                                                                                                              "cursor": null,
                                                                                                                                                                                              "state": {
                                                                                                                                                                                                "cursor": null,
                                                                                                                                                                                                "state": {
                                                                                                                                                                                                  "cursor": null,
                                                                                                                                                                                                  "state": {
                                                                                                                                                                                                    "cursor": null,
                                                                                                                                                                                                    "state": {
                                                                                                                                                                                                      "cursor": null,
                                                                                                                                                                                                      "state": {
                                                                                                                                                                                                        "cursor": null,
                                                                                                                                                                                                        "state": {
                                                                                                                                                                                                          "cursor": null,
                                                                                                                                                                                                          "state": {
                                                                                                                                                                                                            "cursor": null,
                                                                                                                                                                                                            "state": {
                                                                                                                                                                                                              "cursor": null,
                                                                                                                                                                                                              "state": {
                                                                                                                                                                                                                "url": "http://localhost:9888"
                                                                                                                                                                                                              },
                                                                                                                                                                                                              "url": "http://localhost:9888"
                                                                                                                                                                                                            },
                                                                                                                                                                                                            "url": "http://localhost:9888"
                                                                                                                                                                                                          },
                                                                                                                                                                                                          "url": "http://localhost:9888"
                                                                                                                                                                                                        },
                                                                                                                                                                                                        "url": "http://localhost:9888"
                                                                                                                                                                                                      },
                                                                                                                                                                                                      "url": "http://localhost:9888"
                                                                                                                                                                                                    },
                                                                                                                                                                                                    "url": "http://localhost:9888"
                                                                                                                                                                                                  },
                                                                                                                                                                                                  "url": "http://localhost:9888"
                                                                                                                                                                                                },
                                                                                                                                                                                                "url": "http://localhost:9888"
                                                                                                                                                                                              },
                                                                                                                                                                                              "url": "http://localhost:9888"
                                                                                                                                                                                            },
                                                                                                                                                                                            "url": "http://localhost:9888"
                                                                                                                                                                                          },
                                                                                                                                                                                          "url": "http://localhost:9888"
                                                                                                                                                                                        },
                                                                                                                                                                                        "url": "http://localhost:9888"
                                                                                                                                                                                      },
                                                                                                                                                                                      "url": "http://localhost:9888"
                                                                                                                                                                                    },
                                                                                                                                                                                    "url": "http://localhost:9888"
                                                                                                                                                                                  },
                                                                                                                                                                                  "url": "http://localhost:9888"
                                                                                                                                                                                },
                                                                                                                                                                                "url": "http://localhost:9888"
                                                                                                                                                                              },
                                                                                                                                                                              "url": "http://localhost:9888"
                                                                                                                                                                            },
                                                                                                                                                                            "url": "http://localhost:9888"
                                                                                                                                                                          },
                                                                                                                                                                          "url": "http://localhost:9888"
                                                                                                                                                                        },
                                                                                                                                                                        "url": "http://localhost:9888"
                                                                                                                                                                      },
                                                                                                                                                                      "url": "http://localhost:9888"
                                                                                                                                                                    },
                                                                                                                                                                    "url": "http://localhost:9888"
                                                                                                                                                                  },
                                                                                                                                                                  "url": "http://localhost:9888"
                                                                                                                                                                },
                                                                                                                                                                "url": "http://localhost:9888"
                                                                                                                                                              },
                                                                                                                                                              "url": "http://localhost:9888"
                                                                                                                                                            },
                                                                                                                                                            "url": "http://localhost:9888"
                                                                                                                                                          },
                                                                                                                                                          "url": "http://localhost:9888"
                                                                                                                                                        },
                                                                                                                                                        "url": "http://localhost:9888"
                                                                                                                                                      },
                                                                                                                                                      "url": "http://localhost:9888"
                                                                                                                                                    },
                                                                                                                                                    "url": "http://localhost:9888"
                                                                                                                                                  },
                                                                                                                                                  "url": "http://localhost:9888"
                                                                                                                                                },
                                                                                                                                                "url": "http://localhost:9888"
                                                                                                                                              },
                                                                                                                                              "url": "http://localhost:9888"
                                                                                                                                            },
                                                                                                                                            "url": "http://localhost:9888"
                                                                                                                                          },
                                                                                                                                          "url": "http://localhost:9888"
                                                                                                                                        },
                                                                                                                                        "url": "http://localhost:9888"
                                                                                                                                      },
                                                                                                                                      "url": "http://localhost:9888"
                                                                                                                                    },
                                                                                                                                    "url": "http://localhost:9888"
                                                                                                                                  },
                                                                                                                                  "url": "http://localhost:9888"
                                                                                                                                },
                                                                                                                                "url": "http://localhost:9888"
                                                                                                                              },
                                                                                                                              "url": "http://localhost:9888"
                                                                                                                            },
                                                                                                                            "url": "http://localhost:9888"
                                                                                                                          },
                                                                                                                          "url": "http://localhost:9888"
                                                                                                                        },
                                                                                                                        "url": "http://localhost:9888"
                                                                                                                      },
                                                                                                                      "url": "http://localhost:9888"
                                                                                                                    },
                                                                                                                    "url": "http://localhost:9888"
                                                                                                                  },
                                                                                                                  "url": "http://localhost:9888"
                                                                                                                },
                                                                                                                "url": "http://localhost:9888"
                                                                                                              },
                                                                                                              "url": "http://localhost:9888"
                                                                                                            },
                                                                                                            "url": "http://localhost:9888"
                                                                                                          },
                                                                                                          "url": "http://localhost:9888"
                                                                                                        },
                                                                                                        "url": "http://localhost:9888"
                                                                                                      },
                                                                                                      "url": "http://localhost:9888"
                                                                                                    },
                                                                                                    "url": "http://localhost:9888"
                                                                                                  },
                                                                                                  "url": "http://localhost:9888"
                                                                                                },
                                                                                                "url": "http://localhost:9888"
                                                                                              },
                                                                                              "url": "http://localhost:9888"
                                                                                            },
                                                                                            "url": "http://localhost:9888"
                                                                                          },
                                                                                          "url": "http://localhost:9888"
                                                                                        },
                                                                                        "url": "http://localhost:9888"
                                                                                      },
                                                                                      "url": "http://localhost:9888"
                                                                                    },
                                                                                    "url": "http://localhost:9888"
                                                                                  },
                                                                                  "url": "http://localhost:9888"
                                                                                },
                                                                                "url": "http://localhost:9888"
                                                                              },
                                                                              "url": "http://localhost:9888"
                                                                            },
                                                                            "url": "http://localhost:9888"
                                                                          },
                                                                          "url": "http://localhost:9888"
                                                                        },
                                                                        "url": "http://localhost:9888"
                                                                      },
                                                                      "url": "http://localhost:9888"
                                                                    },
                                                                    "url": "http://localhost:9888"
                                                                  },
                                                                  "url": "http://localhost:9888"
                                                                },
                                                                "url": "http://localhost:9888"
                                                              },
                                                              "url": "http://localhost:9888"
                                                            },
                                                            "url": "http://localhost:9888"
                                                          },
                                                          "url": "http://localhost:9888"
                                                        },
                                                        "url": "http://localhost:9888"
                                                      },
                                                      "url": "http://localhost:9888"
                                                    },
                                                    "url": "http://localhost:9888"
                                                  },
                                                  "url": "http://localhost:9888"
                                                },
                                                "url": "http://localhost:9888"
                                              },
                                              "url": "http://localhost:9888"
                                            },
                                            "url": "http://localhost:9888"
                                          },
                                          "url": "http://localhost:9888"
                                        },
                                        "url": "http://localhost:9888"
                                      },
                                      "url": "http://localhost:9888"
                                    },
                                    "url": "http://localhost:9888"
                                  },
                                  "url": "http://localhost:9888"
                                },
                                "url": "http://localhost:9888"
                              },
                              "url": "http://localhost:9888"
                            },
                            "url": "http://localhost:9888"
                          },
                          "url": "http://localhost:9888"
                        },
                        "url": "http://localhost:9888"
                      },
                      "url": "http://localhost:9888"
                    },
                    "url": "http://localhost:9888"
                  },
                  "url": "http://localhost:9888"
                },
                "url": "http://localhost:9888"
              },
              "url": "http://localhost:9888"
            },
            "url": "http://localhost:9888"
          },
          "url": "http://localhost:9888"
        },
        "url": "http://localhost:9888"
      },
      "url": "http://localhost:9888"
    },
    "ecs.version": "1.6.0"
  }
}
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 8, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Dec 8, 2022
@efd6
Copy link
Contributor

efd6 commented Dec 8, 2022

evalWith is returning the unprocessed activation on error. I am working on a clean way to avoid this.

andrewkroh pushed a commit that referenced this issue Dec 8, 2022
Previously, when an error in evaluation or result deserialisation
occurred, the entire input activation container was returned instead of
a valid state. The result of this was that the state would nest on each
iteration of the eval event loop. In cases where errors can happen
frequently, this can result in unbounded memory use.

Also improve the robustness of the want_more flag; the old code would
continue with the loop if state["want_more"] was unset since any(nil)
does not equal false.

Relates: #33992
mergify bot pushed a commit that referenced this issue Dec 8, 2022
Previously, when an error in evaluation or result deserialisation
occurred, the entire input activation container was returned instead of
a valid state. The result of this was that the state would nest on each
iteration of the eval event loop. In cases where errors can happen
frequently, this can result in unbounded memory use.

Also improve the robustness of the want_more flag; the old code would
continue with the loop if state["want_more"] was unset since any(nil)
does not equal false.

Relates: #33992
(cherry picked from commit f08eed8)
efd6 added a commit that referenced this issue Dec 8, 2022
…33997)

Previously, when an error in evaluation or result deserialisation
occurred, the entire input activation container was returned instead of
a valid state. The result of this was that the state would nest on each
iteration of the eval event loop. In cases where errors can happen
frequently, this can result in unbounded memory use.

Also improve the robustness of the want_more flag; the old code would
continue with the loop if state["want_more"] was unset since any(nil)
does not equal false.

Relates: #33992
(cherry picked from commit f08eed8)

Co-authored-by: Dan Kortschak <[email protected]>
chrisberkhout pushed a commit that referenced this issue Jun 1, 2023
Previously, when an error in evaluation or result deserialisation
occurred, the entire input activation container was returned instead of
a valid state. The result of this was that the state would nest on each
iteration of the eval event loop. In cases where errors can happen
frequently, this can result in unbounded memory use.

Also improve the robustness of the want_more flag; the old code would
continue with the loop if state["want_more"] was unset since any(nil)
does not equal false.

Relates: #33992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants