Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 17 19:13

    robjtede on master

    tweak migration document (compare)

  • Feb 17 08:12
    stanley355 commented #2650
  • Feb 17 01:07
    stanley355 commented #2650
  • Feb 16 14:10
    robjtede commented #2650
  • Feb 16 14:09
    robjtede labeled #2650
  • Feb 16 14:09
    robjtede closed #2650
  • Feb 16 14:09
    robjtede commented #2650
  • Feb 16 12:53
    stanley355 opened #2650
  • Feb 16 03:44

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ 5… (compare)

  • Feb 16 03:32

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ f… (compare)

  • Feb 16 03:13

    robjtede on test-v0.1.0-beta.13

    (compare)

  • Feb 16 03:13

    robjtede on http-test-v3.0.0-beta.13

    (compare)

  • Feb 16 03:13

    robjtede on master

    prepare actix-http-test release… prepare actix-test release 0.1.… (compare)

  • Feb 16 03:13

    github-actions[bot] on gh-pages

    Deploying to gh-pages from @ a… (compare)

  • Feb 16 03:11

    robjtede on actors-v4.0.0-beta.12

    (compare)

  • Feb 16 03:11

    robjtede on master

    prepare actix-web-actors releas… (compare)

  • Feb 16 03:10

    robjtede on awc-v3.0.0-beta.21

    (compare)

  • Feb 16 03:10

    robjtede on master

    prepare awc release 3.0.0-beta.… (compare)

  • Feb 16 03:07

    robjtede on http-v3.0.0-rc.3

    (compare)

  • Feb 16 03:07

    robjtede on master

    prepare actix-http release 3.0.… (compare)

Erlend Langseth
@Ploppz
what should I replace actix_web::test::start with in actix-web 4.0.0-beta.8?
1 reply
christian
@christian:matrix.boseck.net
[m]

Hello, I have a question how to use add a validator for an object passed via json.
My Request Handler looks like this.

pub async fn handle(req_args: web::Json<HashMap<String, String>>, r: HttpRequest, auth: BasicAuth, app_state_wrapper: web::Data<AppStateWrapper<T, F>>) -> impl Responder {
...
}

Now I want to validate that the Strings of the HashMap do not contain controll characters.

struct Wrapper {

#[validate(length(min = 1), custom = "my_validator")]
content: HashMap<String, String>
}

Unfortunatly I can't change the client-side to send this wrapper object.
Do you have any ideas for me how to do this?

3 replies
rkfox
@rkfox
I'm having an issue with actix-web4-beta.8 locking up after ~3k post requests in about 20-30 seconds. I'm not really sure what the issue is. The server just won't accept new connections anymore and doesn't recover. No errors are thrown. I tried upping some of the worker connection values, but nothing has fixed the issue.
Vital Leshchyk
@itcreator

Hello there

There is an example https://github.com/actix/examples/tree/master/json/json_decode_error

This example returns error information as a simple text.

Json deserialize error: missing field `name` at line 1 column 16

But it is not so user-friendly. Is it possible to get some struct with error info? E.g:

{
errors: [
{
    "field": "name",
    "reason": "missing field",
    "line": 1,
    "column": 16
},
{
    "field": "address.countryCode",
    "reason": "Wrong country code abcd `ABCD`",
},
{
    "field": "age",
    "reason": "Should be between 0 and 100 years",
},

{
    "field": "email",
    "reason":  [
        "Too long",
        "Incorrect email format"
    ],
}
]
}

Looks like it is a restriction of serde_json not actix-web

Thanks

Christopher Fleetwood
@FL33TW00D
Does anyone have a new example of implementing middleware in actix4 beta?
1 reply
liam-prog
@liam-prog
Hi, How can i run an async function in Actor handler for insert an item in database. please help me i'm new in rust and websocket
impl Handler<MessageChat> for MessageStore {
    type Result = Result<(Uuid,), Error>;

    fn handle(&mut self, msg: MessageChat, ctx: &mut Self::Context) -> Self::Result {
        // Here i need to run async function and getting result
    }
}
Tanner Wilcox
@twiclo
HttpServer::new(move || {
  App::new()
    .service(web::scope("/cables")
      .service(web::resource("")
        .route(web::get().to(utils::get::<Cable>))
        .route(web::post().to(utils::add::<Cable>)))
If I give utils::add::<Cable> the wrong json, like maybe a string instead of a number, actix will just spit back a 400 because I'm assuming the serde part failed
Can I intercept this error somehow to actually tell the user what they did wrong?
Félix
@felix.maneville:qonfucius.team
[m]

Hello, I have a question about the Data<T> we pass to actix web's App. I want to allow concurrent writing to it with custom RwLock inside T.

Basically I have a big Hashmap<String, MyType>, I want to lock every MyType to avoir concurrent writing but I don't want to lock the entire Hashmap

Is it possible or will actix automatically lock the Data<T> object?
1 reply
So I can have a hashmap of RwLock stuff, thanks !
Félix
@felix.maneville:qonfucius.team
[m]
What is the difference between App data and app_data ?
1 reply
Okay, so we can use an Arc directly
1 reply
Félix
@felix.maneville:qonfucius.team
[m]

I'm having some issue with redis integration. A redis::Connection needs to be mutable in order to write something (in my case, a queue with XADD). So I have to use a RwLock for the redis connection in my app_data and it slows down the API a lot:

  • without redis I have 70k operations done in 60s
  • with redis I have barely 30k

Since the Connection is a Pin<Box<>> I thought I could also clone it but it doesn't seem to work.

How do other people handle redis connections using actix?

sanchezroselly
@sanchezroselly
hi, a beginner issue. i am running 'sqlx_todo' example and when posting a json to the server, i get "Error trying to create new todo".
i have used wireshark to check my post and it looks nice. i follow all the instructions in readme.md except setting up username and password, because it does not make sense using sqlite.
does anyone have some skills on this example? thanks everyone.
Mehmet ERİBOL
@mehmeteribol_gitlab
hi. i am tring to implement a middleware example with beta-rc9 version.
fn call(&self, req: S::Request) -> Self::Future { TimeoutServiceResponse { fut: self.service.call(req), sleep: Sleep::new(clock::now() + self.timeout), } }
and it gives error: "fn call(&self, req: S::Request) -> Self::Future {
| ^^^^^^^ associated type Request not found"
asonix (he/they)
@asonix:matrix.asonix.dog
[m]
Request is no longer an associated type on the Service and Transform traits, it is a generic argument to the trait
so S::Request is no longer a valid type
Mehmet ERİBOL
@mehmeteribol_gitlab
I got this codes from api docs. Do i have to remove it?
asonix (he/they)
@asonix:matrix.asonix.dog
[m]
It looks like the documentation is not correct. https://docs.rs/actix-web/4.0.0-beta.9/actix_web/dev/trait.Transform.html in the example Service implementation, the second argument to the call method should be of type Req, not of type S::Request
Mehmet ERİBOL
@mehmeteribol_gitlab
thank you, error is gone
Yoric
@dotyoric:matrix.org
[m]
Hi
I'm trying to write code that uses both actix-web and matrix-rust-sdk.
(i.e. I'm writing a bot with a web API)
Unfortunately, both libs seem to want to take control on the main thread.
  1. Afaict, the future returned by HttpServer.run() only resolves when we shutdown the webserver.
  1. Afaict, it's the same thing for the matrix-rust-sdk.
  1. According to my experiments, it looks like HttpServer::run cannot be called from a tokio::task::spawn.
Am I missing something?
robjtede
@robjtede:matrix.org
[m]
easiest trick here is to launch actix-web server in a new std thread
Yoric
@dotyoric:matrix.org
[m]
Oh, that would work? I assumed that the #[actix_web::main] was doing some magic.
dotyoric:matrix.org @dotyoric:matrix.org will try that.
Yoric
@dotyoric:matrix.org
[m]
robjtede: Do I have to somehow spin some kind of executor on that thread?
robjtede
@robjtede:matrix.org
[m]
Yoric
@dotyoric:matrix.org
[m]
Otherwise, I won't be able to await HttpServer::run.
robjtede
@robjtede:matrix.org
[m]
std::thread::spawn(move || {
  actix_web::rt::System::new().block_on(async move {
     ...
  })
})
Yoric
@dotyoric:matrix.org
[m]
Note: it's System::new("some name").
robjtede
@robjtede:matrix.org
[m]
right, in v3, yes
Yoric
@dotyoric:matrix.org
[m]
Also, it works :) Thanks!
(now attempting to deploy a MVP)
quambene
@quambene

Consider an endpoint for post requests via post macro (https://docs.rs/actix-web/3.3.2/actix_web/attr.post.html). For example using #[post("/login")].

Is it possible to define the path elsewhere like const LOGIN: &str = "/login" and use it in the post macro? I would like to collect all endpoints at one place.

I couldn't make it work. I tried #[post(LOGIN)] and #[post("{}", LOGIN)] as well as #[post("{LOGIN}")] but without success.

Cheers

3 replies
robjtede
@robjtede:matrix.org
[m]
rkfox
@rkfox
Are wildcard routes supported? ie.
#[get("/files/*"
I'm not sure what happened; I thought this was working before. But now this wildcard route is not working.
rkfox
@rkfox
I was using one of the betas previously; maybe v4.0.0-beta.4 but I can't seem to get it working again. I think it broke after upgrading to beta.8.
1 reply
Stepan Kuzmin
@stepankuzmin

Hi everyone!

I'm getting thread panic in runtime after upgrading actix from 0.10 to either 0.11 or 0.12 with

thread 'main' panicked at '`spawn_local` called from outside of a `task::LocalSet`', /Users/stepan/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/task/local.rs:305:18

The only change I've made to my code is that I've removed the name argument from the actix::System::new:

let sys = actix::System::new();

let db = SyncArbiter::start(3, move || DbActor(pool.clone()));
let coordinator: Addr<_> = CoordinatorActor::default().start();

HttpServer::new(move || {
    let state = create_state(db.clone(), coordinator.clone(), config.clone());

    let cors_middleware = Cors::default().allow_any_origin();

    App::new()
        .data(state)
        .wrap(cors_middleware)
        .wrap(middleware::NormalizePath::new(
            middleware::normalize::TrailingSlash::MergeOnly,
        ))
        .wrap(middleware::Logger::default())
        .wrap(middleware::Compress::default())
        .configure(router)
})
.bind(listen_addresses.clone())
.unwrap_or_else(|_| panic!("Can't bind to {}", listen_addresses))
.keep_alive(keep_alive)
.shutdown_timeout(0)
.workers(worker_processes)
.run();

sys.run()

My current dependencies are

actix = "0.12"
actix-cors = "0.5.4"
actix-rt = "1.1"
actix-web = "3.3.2"

What am I missing?

Stepan Kuzmin
@stepankuzmin

I got it

actix 0.12 depends on actix-rt 2 which is not compat with actix-rt 1

Namely this pattern would not work anymore.
let sys = System::new();
HttpServer::run();
Instead it should be changed to something like this.
System::new().block_on(some_future)