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

Revert "Add rate limiting to server endpoints" #4910

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions openhands/server/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
import requests
from pathspec import PathSpec
from pathspec.patterns import GitWildMatchPattern
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address

from openhands.security.options import SecurityAnalyzers
from openhands.server.data_models.feedback import FeedbackDataModel, store_feedback
Expand Down Expand Up @@ -97,36 +94,6 @@ async def lifespan(app: FastAPI):

security_scheme = HTTPBearer()

# Initialize rate limiter
limiter = Limiter(
key_func=get_remote_address,
default_limits=['5 per second'],
strategy='moving-window', # Use a sliding window for more accurate rate limiting
)
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)


# Apply stricter limits to auth endpoints
def get_path_limits(request: Request):
path = request.url.path
if path == '/ws' or path in ['/api/github/callback', '/api/authenticate']:
return ['1 per second']
return ['5 per second']


@app.middleware('http')
async def rate_limit_middleware(request: Request, call_next):
limits = get_path_limits(request)
try:
await limiter.check_request_limit(request, limits=limits)
except RateLimitExceeded:
return JSONResponse(
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
content={'error': 'Too many requests'},
)
return await call_next(request)


def load_file_upload_config() -> tuple[int, bool, list[str]]:
"""Load file upload configuration from the config object.
Expand Down Expand Up @@ -293,13 +260,6 @@ async def attach_session(request: Request, call_next):

@app.websocket('/ws')
async def websocket_endpoint(websocket: WebSocket):
try:
# Create a mock request object for rate limiting
mock_request = Request(scope={'type': 'http', 'client': websocket.client})
await limiter.check_request_limit(mock_request, limits=['1 per second'])
except RateLimitExceeded:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)
return
"""WebSocket endpoint for receiving events from the client (i.e., the browser).
Once connected, the client can send various actions:
- Initialize the agent:
Expand Down
53 changes: 1 addition & 52 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ opentelemetry-api = "1.25.0"
opentelemetry-exporter-otlp-proto-grpc = "1.25.0"
modal = "^0.64.145"
runloop-api-client = "0.7.0"
slowapi = "^0.1.9"

[tool.poetry.group.llama-index.dependencies]
llama-index = "*"
Expand Down Expand Up @@ -94,7 +93,6 @@ reportlab = "*"
[tool.coverage.run]
concurrency = ["gevent"]


[tool.poetry.group.runtime.dependencies]
jupyterlab = "*"
notebook = "*"
Expand Down Expand Up @@ -125,7 +123,6 @@ ignore = ["D1"]
[tool.ruff.lint.pydocstyle]
convention = "google"


[tool.poetry.group.evaluation.dependencies]
streamlit = "*"
whatthepatch = "*"
Expand Down
Loading