Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
HoboMan
Nov 4, 2010

my code as it stands

C# code:
public IHttpActionResult SubmitForm([FromBody]string json)
{
    var purchaseOrder = JsonConvert.DeserializeObject<PurchaseOrder>(json, defaultSettings);
    using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
    {
        try
        {
            // submit the info into the database
        }
        catch(SqlException e)
        {
            logger.error(connection , "Exception saving purchase order", e);
            return InternalServerError();
        }
    }
    Task.Run( () =>
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
            {
                try
                {
                    // send email
                    logger.debug(connection , "Sent email");
                }
                catch(Exception e)
                {
                    logger.error(connection , "Exception sending email", e);
                }
            }
        });
    return Ok();
}
"Sent email" will get logged, but if i hard code an exception in the try block "Exception sending email" will not get logged.

e: i literally just added the using and Task.Run blocks around the existing try-catch that was there.

e2: i forgot to include the try-catch for the json parsing, but you get the idea

HoboMan fucked around with this message at 21:39 on Oct 11, 2018

Adbot
ADBOT LOVES YOU

jeffery
Jan 1, 2013
he has an exception programmed in the a.i. to override the blockade of his suicide

HoboMan
Nov 4, 2010

jeffery posted:

he has an exception programmed in the a.i. to override the blockade of his suicide

:hmmyes:

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

brand engager posted:

is that dude a bot and/or having a psychotic break

Por qué no los dos

jeffery
Jan 1, 2013
your speakin about urself dumbass

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


HoboMan posted:

my code as it stands

C# code:
public IHttpActionResult SubmitForm([FromBody]string json)
{
    var purchaseOrder = JsonConvert.DeserializeObject<PurchaseOrder>(json, defaultSettings);
    using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
    {
        try
        {
            // submit the info into the database
        }
        catch(SqlException e)
        {
            logger.error(connection , "Exception saving purchase order", e);
            return InternalServerError();
        }
    }
    Task.Run( () =>
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
            {
                try
                {
                    // send email
                    logger.debug(connection , "Sent email");
                }
                catch(Exception e)
                {
                    logger.error(connection , "Exception sending email", e);
                }
            }
        });
    return Ok();
}
"Sent email" will get logged, but if i hard code an exception in the try block "Exception sending email" will not get logged.

e: i literally just added the using and Task.Run blocks around the existing try-catch that was there.

e2: i forgot to include the try-catch for the json parsing, but you get the idea

has your logger got any sort of session dependency? async threads don't share/inherit session so that can just silently dump stuff there's something like "log the current session user Id in the trace" when there is no session user id


i had a very similar use case with emails where the factor was that the attachment to the mail could take more than the web timeout to generate, so the mail would kick off in another thread and the user would get a "sending mail" response into their browser but they might then get an email going "this timed out after x seconds" 5 mins later

Edit: just realised this makes no sense as the start trace is logged. For my case I actually gave up using tasks because I had some weird issues and just used a manually created thread instead.

Powerful Two-Hander fucked around with this message at 22:09 on Oct 11, 2018

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.

HoboMan posted:

my code as it stands

C# code:
public IHttpActionResult SubmitForm([FromBody]string json)
{
    var purchaseOrder = JsonConvert.DeserializeObject<PurchaseOrder>(json, defaultSettings);
    using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
    {
        try
        {
            // submit the info into the database
        }
        catch(SqlException e)
        {
            logger.error(connection , "Exception saving purchase order", e);
            return InternalServerError();
        }
    }
    Task.Run( () =>
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
            {
                try
                {
                    // send email
                    logger.debug(connection , "Sent email");
                }
                catch(Exception e)
                {
                    logger.error(connection , "Exception sending email", e);
                }
            }
        });
    return Ok();
}
"Sent email" will get logged, but if i hard code an exception in the try block "Exception sending email" will not get logged.

e: i literally just added the using and Task.Run blocks around the existing try-catch that was there.

e2: i forgot to include the try-catch for the json parsing, but you get the idea

I feel like I oughta know this better after having hosed with C# for a minute, but Task.Run creates, starts, and returns a Task; if you were expecting an exception to propagate _out_ of your Task than I think you'd need to await the Task returned by Task.Run. It seems like the exception handling should happen regardless of whether you await the Task.

Night Shade
Jan 13, 2013

Old School
Bet logger is getting disposed when the request completes, and the task is silently discarding an object disposed exception

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

HoboMan posted:

but i am also that guy!!!

see thread title

redleader
Aug 18, 2005

Engage according to operational parameters
any exceptions logged in the windows event log?

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

Night Shade posted:

Bet logger is getting disposed when the request completes, and the task is silently discarding an object disposed exception

Yeah I'm thinking this, as well.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

HoboMan posted:

my code as it stands

"Sent email" will get logged, but if i hard code an exception in the try block "Exception sending email" will not get logged.

e: i literally just added the using and Task.Run blocks around the existing try-catch that was there.

e2: i forgot to include the try-catch for the json parsing, but you get the idea

Task.ContinueWith should be what you want

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Zlodo posted:

phonetically Q is butt in french so it makes sense

lol

current q report: working with dates feels really nice but q is hella weakly typed so this is biting me a lot

like check this out

code:
q) handle_variable:hopen `:localhost:5010     / connects to a q server at localhost:5010 and assigns to handle_variable
q) handle_variable "2i+2i+2i"                 / you can execute q code at the server this way
6i
q) handle_variable                            / it's... actually just an int32?
428i
q) 428i "2i+2i+2i"                            / so you can also execute at the server this way. applying a string to the int32.
6i

HoboMan
Nov 4, 2010

huh?

redleader
Aug 18, 2005

Engage according to operational parameters

Symbolic Butt posted:

lol

current q report: working with dates feels really nice but q is hella weakly typed so this is biting me a lot

like check this out

code:
q) handle_variable:hopen `:localhost:5010     / connects to a q server at localhost:5010 and assigns to handle_variable
q) handle_variable "2i+2i+2i"                 / you can execute q code at the server this way
6i
q) handle_variable                            / it's... actually just an int32?
428i
q) 428i "2i+2i+2i"                            / so you can also execute at the server this way. applying a string to the int32.
6i

this goes well beyond "weakly typed" and into "insanely typed"

Nomnom Cookie
Aug 30, 2009



implicitly converts int to remote code execution, that’s even more impressively cracked than c++

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

redleader posted:

this goes well beyond "weakly typed" and into "insanely typed"

it’s just automatic promotion of an arbitrary integer to a pointer, what’s the worst that could happen

Luigi Thirty
Apr 30, 2006

Emergency confection port.

we did it

https://twitter.com/LuigiThirty/status/1051017321941270528

AWWNAW
Dec 30, 2008

HoboMan posted:

my code as it stands

C# code:
public IHttpActionResult SubmitForm([FromBody]string json)
{
    var purchaseOrder = JsonConvert.DeserializeObject<PurchaseOrder>(json, defaultSettings);
    using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
    {
        try
        {
            // submit the info into the database
        }
        catch(SqlException e)
        {
            logger.error(connection , "Exception saving purchase order", e);
            return InternalServerError();
        }
    }
    Task.Run( () =>
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myDatabase"].ConnectionString))
            {
                try
                {
                    // send email
                    logger.debug(connection , "Sent email");
                }
                catch(Exception e)
                {
                    logger.error(connection , "Exception sending email", e);
                }
            }
        });
    return Ok();
}
"Sent email" will get logged, but if i hard code an exception in the try block "Exception sending email" will not get logged.

e: i literally just added the using and Task.Run blocks around the existing try-catch that was there.

e2: i forgot to include the try-catch for the json parsing, but you get the idea

you should look to use HostingEnvironment.QueueBackgroundWorkItem
as described in this lovely blog post https://blogs.msdn.microsoft.com/webdev/2014/06/04/queuebackgroundworkitem-to-reliably-schedule-and-run-background-processes-in-asp-net/ which just happens to be about sending email too

any time you're doing "long running" work in ASP.NET (you never should) you're subject to the AppPool being recycled and all that poo poo. MS realized people were not going to figure out this is a bad idea so they added this

dick traceroute
Feb 24, 2010

Open the pod bay doors, Hal.
Grimey Drawer
Alternatively just fart out to a service like sendgrid. May not be an option, but their free plan is quite generous

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


AWWNAW posted:

you should look to use HostingEnvironment.QueueBackgroundWorkItem
as described in this lovely blog post https://blogs.msdn.microsoft.com/webdev/2014/06/04/queuebackgroundworkitem-to-reliably-schedule-and-run-background-processes-in-asp-net/ which just happens to be about sending email too

any time you're doing "long running" work in ASP.NET (you never should) you're subject to the AppPool being recycled and all that poo poo. MS realized people were not going to figure out this is a bad idea so they added this

lmao at the first sentence in that being "there are loads of stack overflow questions about this" IDK maybe that's because you guys embed this stuff in random blog posts where it's impossible to find?

ColTim
Oct 29, 2011

Is that the one where if you negate it the code gets run async?

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

ColTim posted:

Is that the one where if you negate it the code gets run async?

yes!

brap
Aug 23, 2004

Grimey Drawer
- Scheduled work items are not guaranteed to ever execute, once the app pool starts to shut down, QueueBackgroundWorkItem calls will not be honored.

lol. deal with this by fixing the mail server if you possibly can. otherwise if you want things to actually get delivered it sounds like you need to store the pending emails in a persistent queue.

Finster Dexter
Oct 20, 2014

Beyond is Finster's mad vision of Earth transformed.

brap posted:

- Scheduled work items are not guaranteed to ever execute, once the app pool starts to shut down, QueueBackgroundWorkItem calls will not be honored.

lol. deal with this by fixing the mail server if you possibly can. otherwise if you want things to actually get delivered it sounds like you need to store the pending emails in a persistent queue.

Yeah, I don't see what this QueueBackgroundWorkItem actually gets you if the calls won't be honored when the AppPool shuts down. Like, I already had that just spinning up background workers.

redleader
Aug 18, 2005

Engage according to operational parameters
the difference between QBWI and some random threadpool worker is that ASP.NET is aware of stuff queued by the former, and will notify background items about impending app pool recycles etc and give them a grace period before it kills them. this gives the worker an opportunity to gracefully stop doing its thing

with a normal threadpool worker, ASP.NET doesn't know of its existence and will just kill it immediately on app pool recycle

i also think there's a difference in how uncaught exceptions are handled - maybe QBWI won't kill the process on unhandled exceptions, while the same thing in a normal thread will? not sure on this point though

QBWI is a wrapper around HostingEnvironment.RegisterObject by people who know what they are doing. this is weird low level ASP.NET poo poo that most people have no business loving about with

naturally, RegisterObject is used in some very important bits of our codebase

redleader fucked around with this message at 02:57 on Oct 14, 2018

redleader
Aug 18, 2005

Engage according to operational parameters
or just read this which is basically the canonical "why you shouldn't run stuff in background threads in ASP.NET" and is far better than my lovely post. note that it was written before QBWI was introduced, but is still an excellent reference

AggressivelyStupid
Jan 9, 2012

ctps: hosed around and got Azure Devops working at work building a deploying some dumb little toy project


At the risk of being shaggar, it's pretty good but also clearly a work in progress

Soricidus
Oct 21, 2010
freedom-hating statist shill
ctps: somehow I’ve ended up writing a perl script

FlapYoJacks
Feb 12, 2009
Probation
Can't post for 33 hours!

Soricidus posted:

ctps: somehow I’ve ended up writing a perl script

shameful.

akadajet
Sep 14, 2003

i think i had one college class that required writing perl scripts and that's the last i've seen of it lol

AggressivelyStupid
Jan 9, 2012

my experience with perl is thus:



At least it isn't php

JawnV6
Jul 4, 2004

So hot ...
i took a perl class at intel with someone whose entire programming history until that point was test assembly

not like, your normal kind of assembly that a compiler spits out, but problem statements like "exercise this pin" and writing raw x86 asm to hit that condition. so every little thing where the professor was trying to explain, say, flow control with a for() loop, this guy would break down in tears at how much heavy lifting the language was doing for him

for a while my pseudocode would come out half a step away from perl, it's kinda nice that i've devolved down into C

mod saas
May 4, 2004

Grimey Drawer

JawnV6 posted:

so every little thing where the professor was trying to explain, say, flow control with a for() loop, this guy would break down in tears at how much heavy lifting the language was doing for him

joy or frustration?

JawnV6
Jul 4, 2004

So hot ...

mod saas posted:

joy or frustration?

bittersweet, lil from column A, lil from column B

his job presumably still had a lot of straight-line assembly or he may have, like me, figured out perl spits out asm p. good

Chamook
Nov 17, 2006

wheeeeeeeeeeeeee
ctps: convinced work that it would be a good idea for me to learn swift and get a trained up on our iOS app. I only vaguely remember mvvm and the iOS devs do not like how much of a functional weenie f# has made me. Feelin' extra terrible rn :grin:

AWWNAW
Dec 30, 2008

people that don’t appreciate functional programming are bad people

tef
May 30, 2004

-> some l-system crap ->
i liked perl

FlapYoJacks
Feb 12, 2009
Probation
Can't post for 33 hours!
from what I have been told:

Perl is good if you want to write a script that uses regex or does a lot of math.

I think that’s about it.

Adbot
ADBOT LOVES YOU

akadajet
Sep 14, 2003

ratbert90 posted:

from what I have been told:

Perl is good if you want to write a script that uses regex or does a lot of math.

I think that’s about it.

i mean, python can do that too and isn't nearly as ugly

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply