Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


bweston
2013-04-19T14:21:03Z
I have been trying to add a few useful general server health monitoring jobs lately, such as something similar to what was being asked about in this  thread.

Do you have any idea why the following script might work just fine when run using an Execute task to run it with Powershell, but cause the VisualCron server process to start consuming more and more RAM and then stop completely when run as a Powershell task?

param($address="localhost")
add-type -Path "c:\Program Files (x86)\VisualCron\VisualCron.dll"
add-type -Path "c:\Program Files (x86)\VisualCron\VisualCronAPI.dll"

$c = new-object VisualCronAPI.Client
$conn = new-object VisualCronAPI.Connection
$conn.Address = $address
$conn.UserName = 'usernameRedacted'
$conn.Password = 'passwordRedacted'
$s = $c.Connect($conn,$true)

$j = $s.Jobs.GetAll()  | ?{$_.Stats.Status -eq "Running" -and $_.Stats.DateLastExecution -lt (get-date).AddHours(-2)}

$j | select-object Group, Name
$c.Disconnect($s)
Sponsor
Forum information
bbusse
2013-04-19T14:32:39Z
Does this happen when using a PowerShell task pointing to a PS1 file, a PowerShell task with the code pasted in, or both?

I assume for your execute task that doesn't cause any issues you're just pointing to POWERSHELL.exe and then the path to the PS1 file as the argument?

I haven't seen/noticed this before but am curious to know what sort of schedule you run this task on and generally how long before it causes issues?

Also, what version of VisualCron are you running?

EDIT: Actually, I just used the exact code (pasted into a PowerShell task) that you have listed above on my 6.2.1 install of VisualCron and memory usage jumped from 49mb up to around 150mb or so for about 3-4 seconds and then the service stopped alltogether. I had to start the 'VisualCron' service again. Did this to me twice. Interesting result.

Brian
bbusse
2013-04-19T15:09:26Z
Henrik,

I turned on Debugging on my system and launched the task I created for testing memory usage on VisualCron. The log below is from the point of running the task until the end of the log file, which is when the service stops. Likely a crash, as I see no stopping service message. The code is using the 'admin' id with a password I have set, FYI.



4/19/2013 10:03:09 AM	Debug	Job (1) was added to processlist: Test Powershell Memory Usage
4/19/2013 10:03:09 AM	Debug	Next action: ActionContinue
4/19/2013 10:03:09 AM	Debug	Next Task is: List Jobs running more than 2 hours
4/19/2013 10:03:09 AM	Debug	Calling StartTaskProcess() with Task: List Jobs running more than 2 hours (0)
4/19/2013 10:03:10 AM	Debug	Task (230) was added to processlist: List Jobs running more than 2 hours
4/19/2013 10:03:10 AM	Debug	Entering wait loop. List Jobs running more than 2 hours (230)
4/19/2013 10:03:10 AM	Info	Task started: List Jobs running more than 2 hours (230)
4/19/2013 10:03:10 AM	Debug	Before impersonation
4/19/2013 10:03:10 AM	Debug	Before runspace.CreateRunspace
4/19/2013 10:03:10 AM	Debug	Before runspace.ThreadOptions
4/19/2013 10:03:10 AM	Debug	Before runspace.Open
4/19/2013 10:03:10 AM	Debug	Success opening Runspace(1): UseCurrentThread
4/19/2013 10:03:10 AM	Debug	Before runspace.CreatePipeline
4/19/2013 10:03:10 AM	Debug	Before runspace.Invoke
4/19/2013 10:03:10 AM	Debug	TcpClient accepted.
4/19/2013 10:03:10 AM	Debug	Before sending ClientConnection.
4/19/2013 10:03:10 AM	Debug	New client connected.
4/19/2013 10:03:10 AM	Debug	Before returning sslStream
4/19/2013 10:03:10 AM	Debug	AuthenticateAsServer, certificate name: CN=vc
4/19/2013 10:03:10 AM	Debug	AuthenticateAsServer doneCN=vc
4/19/2013 10:03:10 AM	Debug	Waiting for client connection
4/19/2013 10:03:16 AM	Debug	Using normal logon (False)
4/19/2013 10:03:16 AM	Info	Verifying license, loaded (True)
4/19/2013 10:03:16 AM	Debug	License status (VerifyLicense):  Activated
4/19/2013 10:03:16 AM	Info	User "VisualCron Default Admin" (admin) - Logged in succesfully through Socket (e090763e-9123-45ca-8169-b3d79c14e65f)
4/19/2013 10:03:16 AM	Debug	Updating login status for: e090763e-9123-45ca-8169-b3d79c14e65f
4/19/2013 10:03:16 AM	Debug	Before sending ClientConnection.
4/19/2013 10:03:16 AM	Comm	IN: SERVERSETTINGSREQ
4/19/2013 10:03:16 AM	Debug	Server time: 4/19/2013 10:03:16 AM
4/19/2013 10:03:16 AM	Comm	IN: LICENSEREQ


Brian
bweston
2013-04-19T15:12:03Z
I haven't tested it with a Powershell task pointing to the ps1 file...perhaps I shall. Code pasted in was what I meant. You are correct about the execute task, and yes...your result matches my experience with 6.2.2. I think I remember running into a similar problem once before (several versions ago) with either invoke-restmethod or invoke-sqlcmd.
bbusse
2013-04-19T15:25:52Z
Originally Posted by: bweston 

I haven't tested it with a Powershell task pointing to the ps1 file...perhaps I shall. Code pasted in was what I meant. You are correct about the execute task, and yes...your result matches my experience with 6.2.2. I think I remember running into a similar problem once before (several versions ago) with either invoke-restmethod or invoke-sqlcmd.



I just tried it pointing at a PS1 file, using a PowerShell task. It works just fine.

So, Henrik, We have some sort of issue using the code listed in the first post.

I ran the code without this line below, and there are no problems. So the below line of code is causing the system to crash, when pasted into a PowerShell task. Works otherwise using a PS1 via PowerShell task or Execute task:


j = $s.Jobs.GetAll()  | ?{$_.Stats.Status -eq "Running" -and $_.Stats.DateLastExecution -lt (get-date).AddHours(-2)}


Definately going to need some help with this one, Henrik :)

Brian
bweston
2013-04-19T15:49:57Z
Here's something puzzling. I thought it might be a syntax problem where VisualCron was trying to interpret the scriptblock as a variable, so I tried the Powershell 3 alternate where-object syntax...except it can't drill into the Stats property, so it can't do what I wanted. That worked. But then I tried the simpler query with the normal syntax, and this worked too:

$j = $s.Jobs.GetAll()  | ?{ $_.Group -eq "_TEST" }

bweston
2013-04-19T16:59:26Z
Okay, this is even more peculiar. It seems to work with the original line if I add a space before the closing brace of the where-object block. But not if I also add one after the beginning brace.
Support
2013-04-20T07:01:16Z
Originally Posted by: bbusse 

Originally Posted by: bweston 

I haven't tested it with a Powershell task pointing to the ps1 file...perhaps I shall. Code pasted in was what I meant. You are correct about the execute task, and yes...your result matches my experience with 6.2.2. I think I remember running into a similar problem once before (several versions ago) with either invoke-restmethod or invoke-sqlcmd.



I just tried it pointing at a PS1 file, using a PowerShell task. It works just fine.

So, Henrik, We have some sort of issue using the code listed in the first post.

I ran the code without this line below, and there are no problems. So the below line of code is causing the system to crash, when pasted into a PowerShell task. Works otherwise using a PS1 via PowerShell task or Execute task:


j = $s.Jobs.GetAll()  | ?{$_.Stats.Status -eq "Running" -and $_.Stats.DateLastExecution -lt (get-date).AddHours(-2)}


Definately going to need some help with this one, Henrik :)

Brian



I ran the code and the system did not *crash*. I just found out that removing this part | ?{$_.Stats.Status -eq "Running" -and $_.Stats.DateLastExecution -lt (get-date).AddHours(-2)} makes it work. What I get, which makes no sense, when using the full line is the following:

Exception in Task: The term 'No' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I am no powershell expert so I do not know what it means. If there is any content that looks like or produces a command?

About executing the code we use a "normal" Powershell object and just pass the code. We do not do anything extra with it.

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bweston
2013-04-22T13:11:56Z
Okay, this is a long one...

Based on what we've determined so far, I have an even stronger suspicion than before that what is happening has something to do with VisualCron attempting to parse Powershell scriptblocks as variables. They are both enclosed in {}, the problem only arises when using the Powershell script task in the context that would allow for use of Visualcron variable expressions...both of those seem to fit the hypothesis. The fact that a space before the closing brace of a script block seems to prevent the problem for me fits with the idea of it being a parsing problem, although it's still odd.

I even have a possible explanation for the "'No' is not recognized as the name..." exception that fits this hypothesis, although I don't know why you get that while we get crashes. If I copy that scriptblock and paste it into the Variables window WITH a space before the closing brace, the value preview just gives me back the scriptblock. If I remove the space (making it match the scriptblock that was causing me problems), the value preview changes to:
Quote:

(No match on $_.Stats.Status -eq "Running" -and $_.Stats.DateLastExecution -lt (get-date).AddHours(-2))


Based on messing around a bit more, the specific circumstances under which the preview will give the "No match" message instead of just giving back the string exactly as entered is if the string contains a matched pair of {}, between which neither of those characters appears again, but at least one opening parenthesis does appear and a closing parenthesis is the last character before the }.

To put it in a regular expression: \{[^\{\}]*\([^\{\}]*\)\}

If on your installation Visualcron is actually substituting "No match on..." and so forth into the script to be executed, then the exception you quoted is exactly what Powershell would return. You could probably confirm that by running this, which I believe should display enough of a stack trace to see the substituted text if that's what's happening:


param($address="localhost")
try {
add-type -Path "c:\Program Files (x86)\VisualCron\VisualCron.dll"
add-type -Path "c:\Program Files (x86)\VisualCron\VisualCronAPI.dll"

$c = new-object VisualCronAPI.Client
$conn = new-object VisualCronAPI.Connection
$conn.Address = $address
$conn.UserName = 'usernameRedacted'
$conn.Password = 'passwordRedacted'
$s = $c.Connect($conn,$true)

$j = $s.Jobs.GetAll()  | ?{$_.Stats.Status -eq "Running" -and $_.Stats.DateLastExecution -lt (get-date).AddHours(-2)}

$j | select-object Group, Name
$c.Disconnect($s)
}
catch{
$error | fl * -f
}


...I can't use that to confirm or deny, because that still goes into a runaway memory consumption for me. And of course, that still doesn't answer why you get substitution and we get crashes. I have only tested this on one of my two servers so far; it's running 6.2.2 on Windows Server 2008 64-bit with service pack 2.

What I'm chiefly interested in now is making sure I avoid this in the future. So far, adding a space before the closing brace of all Powershell blocks seems to prevent it, but I don't know whether that will remain reliable in future versions. I didn't find anything in the documentation indicating a way to escape {} characters so that VisualCron's variable substitution parser will ignore them. If there is a way to do that, then I could try that next, and if that also prevents the crash I'll feel a little bit safer about my approach.
Support
2013-04-22T13:21:22Z
Thanks for your reply.

The regex we use for intercepting VisualCron Variables is the following:

\{([^\{\}\[\]\(]+)\(([^\{\}]*)\)\}

What we could do to further tighten this is to allow only capital letters A-Z in the start before the first (. If you can provide such a change to the above regex ( you seem to be the expert on regex here 🙂 )we could test this right away and tell if this removes the problems with crashes etc.


Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bweston
2013-04-22T13:43:55Z
Originally Posted by: Support 

Thanks for your reply.

The regex we use for intercepting VisualCron Variables is the following:

\{([^\{\}\[\]\(]+)\(([^\{\}]*)\)\}

What we could do to further tighten this is to allow only capital letters A-Z in the start before the first (. If you can provide such a change to the above regex ( you seem to be the expert on regex here 🙂 )we could test this right away and tell if this removes the problems with crashes etc.


That would be this:

\{([A-Z]+)\(([^\{\}]*)\)\}

Either of those definitely would not match with a space between the closing parenthesis and the closing brace. That means I need to go back and try one of my tests again, though, because I was almost positive I had one test case that shouldn't have matched but still crashed, which would mean there's something else involved. I'll try to get back to that later today.
Support
2013-04-22T14:33:51Z
Thanks, that change did fix the problem about the "No"-problem. As I never could reproduce the crash I wonder if you need this new version now or if you can wait (by using the blank space workaround) - I was not sure if that prevented the crash or not.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bweston
2013-04-22T14:40:13Z
Originally Posted by: Support 

Thanks, that change did fix the problem about the "No"-problem. As I never could reproduce the crash I wonder if you need this new version now or if you can wait (by using the blank space workaround) - I was not sure if that prevented the crash or not.



So far, that seems to prevent the crash.

The reason I need to go back and run another test when I can afford to interrupt the server for a bit is because I thought I got the crash once when I had spaces both before the closing brace and after the opening brace. It may be that I had another offending script block in that test that threw it off, or that I otherwise screwed up or misremembered the test...but the motivation for testing that again is so that I can let you know if it looks like there's more to the problem; it looks like the space is a sufficient interim solution either way.
Support
2013-04-22T14:42:27Z
Ok, FYI this fix will be included in the 7.0.0 release. We will probably release the first beta in a week and then maybe the final in a month. There are a lot of things we are changing and testing at the moment.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Users browsing this topic
Scroll to Top