Skip to content

how to close connection immediately? #474

@lithbitren

Description

@lithbitren

if client's connection of actix-web is probably attacking, how can I close it immediately and insert the address into a dynamic blocklist?

when a addr is in the blocklist, i don't what to parse the uri or headers from this addr, just close the connection without sending or receiving any of the message.

    let listener = TcpListener::bind(...).await?;

    while let (socket, addr) = listener.accept().await? {

        if blocklist.contains(&addr) {
            continue;
        }

        tokio::spawn(async move {

            ...

            if connection_is_attacking() {
                blocklist.insert(addr);
                connection.close_immediately();
            }

            ...

        });
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions