How to find/fix a "stackoverflow exception in /action_dispatch/middleware/reloader"? - ruby-on-rails-3

I get this Exception sporadic on my production debian / rails 3.2.22.5
EDIT: I know can reproduce it also in development
It feels that it has something to do with caching.
I have a "permission_checker" that is called width almost every call on the server. It checks permission of the object requested - going down all records/models till it finds the final owner of this object/record, and then decides:
when no owner found then 404
when owner found same as logged in user then process page
when owner found is the public owner then process page read only
else raise permission exception
so far so good
The code looks like that (the 'aaa' so on and level error just for debugging)
# some processing to find the owner
# id_val is a hash holding the result of this
logger.error "needed owner id :#{id_val}".yellow
logger.error "aaa".yellow
needed_owner_id=id_val[:person_id]
if needed_owner_id
logger.error "bbb #{needed_owner_id}".yellow
needed_owner=Person.find(needed_owner_id) #<----- here is the crash
logger.error "ccc".yellow
logger.error "needed owner id :#{needed_owner_id} (#{needed_owner.owner_type}".red.on_white
logger.error "ddd".yellow
logger.error "current person id :#{#current_person ? #current_person.id : nil}".red.on_white
else
logger.error "no needed owner found"
end
# further processing
if i don't get the stackoverflow, the output looks like this:
Started GET "/ldc/order_forms/ec0a08a6-8525-4c6e-9056-d387e7ad3b9c/edit"
Processing by Ldc::OrderFormsController#edit as HTML
Parameters: {"id"=>"ec0a08a6-8525-4c6e-9056-d387e7ad3b9c"}
LoginData Load (0.1ms) SELECT `login_data`.* FROM `login_data` WHERE `login_data`.`id` = '083a684f-db0e-4c87-a44e-d434d3334289' LIMIT 1
Ldc::Person Load (0.1ms) SELECT `ldc_people`.* FROM `ldc_people` WHERE `ldc_people`.`ustate` = 'A' AND `ldc_people`.`login_data_id` = '083a684f-db0e-4c87-a44e-d434d3334289' LIMIT 1
check in: {:order_form_id=>"ec0a08a6-8525-4c6e-9056-d387e7ad3b9c", :person_id=>nil}
Ldc::OrderForm Load (0.1ms) SELECT `ldc_order_forms`.* FROM `ldc_order_forms` WHERE `ldc_order_forms`.`ustate` = 'A' AND `ldc_order_forms`.`id` = 'ec0a08a6-8525-4c6e-9056-d387e7ad3b9c' LIMIT 1
CACHE (0.0ms) SELECT `ldc_order_forms`.* FROM `ldc_order_forms` WHERE `ldc_order_forms`.`ustate` = 'A' AND `ldc_order_forms`.`id` = 'ec0a08a6-8525-4c6e-9056-d387e7ad3b9c' LIMIT 1
needed owner id :{:person_id=>"c7285c28-0906-4592-bbd7-3fbe164a337e"}
aaa
bbb c7285c28-0906-4592-bbd7-3fbe164a337e
Ldc::Person Load (0.1ms) SELECT `ldc_people`.* FROM `ldc_people` WHERE `ldc_people`.`ustate` = 'A' AND `ldc_people`.`id` = 'c7285c28-0906-4592-bbd7-3fbe164a337e' LIMIT 1
ccc
needed owner id :c7285c28-0906-4592-bbd7-3fbe164a337e
ddd
current person id :c7285c28-0906-4592-bbd7-3fbe164a337e
--------- permission check done ---------
If it fails then its all the same until the crash:
check in: {:order_form_id=>"ec0a08a6-8525-4c6e-9056-d387e7ad3b9c", :person_id=>nil}
Ldc::OrderForm Load (3.2ms) SELECT `ldc_order_forms`.* FROM `ldc_order_forms` WHERE `ldc_order_forms`.`ustate` = 'A' AND `ldc_order_forms`.`id` = 'ec0a08a6-8525-4c6e-9056-d387e7ad3b9c' LIMIT 1
CACHE (0.0ms) SELECT `ldc_order_forms`.* FROM `ldc_order_forms` WHERE `ldc_order_forms`.`ustate` = 'A' AND `ldc_order_forms`.`id` = 'ec0a08a6-8525-4c6e-9056-d387e7ad3b9c' LIMIT 1
needed owner id :{:person_id=>"c7285c28-0906-4592-bbd7-3fbe164a337e"}
aaa
bbb c7285c28-0906-4592-bbd7-3fbe164a337e
Completed 500 Internal Server Error in 223.8ms
SystemStackError (stack level too deep):
actionpack (3.2.22.5) lib/action_dispatch/middleware/reloader.rb:70
The code for lib/action_dispatch/middleware/reloader.rb:70 is a raise:
def call(env)
#validated = #condition.call
prepare!
response = #app.call(env)
response[2] = ActionDispatch::BodyProxy.new(response[2]) { cleanup! }
response
rescue Exception
cleanup!
raise
end
Any ideas what these lines do, so I can search further?

Related

No more data to read from socket after execute this sql

Why when I execute this SQL using SQL Developer it said
No more data to read from socket
but when I reconnect the connection then remove fetch next 5 rows only it executes perfectly?
It also happens when I execute this query on web application, it gives this error:
oci_execute(): ORA-03113: end-of-file on communication channel
Process ID: 4136
Session ID: 18
Serial number: 36957
SELECT PO_ID,
ENQ_ID,
TITLE,
SYS_BRKDWN_ID,
TECH_HAND_USR_ID,
PROJ_NO,
SUPPL_NO,
approver_usr_id,
VER
FROM S181
WHERE approver_usr_id ='EETEC'
and reject_date is null
AND po_hdr_biz.can_approve(po_id, enq_id, ver,'EETEC') = 1
AND EXISTS (
SELECT NULL
FROM po_approvals
WHERE po_approvals.po_id = s181.po_id
AND po_approvals.ver = s181.ver
AND po_approvals.init = 'EETEC'
AND po_approvals.init = s181.approver_usr_id
AND po_approvals.po_id IS NOT NULL
AND po_approvals.approve_date IS NULL
UNION
SELECT NULL
FROM po_approvals
WHERE po_approvals.enq_id = s181.enq_id
AND po_approvals.ver = s181.ver
AND po_approvals.init = 'EETEC'
AND po_approvals.init = s181.approver_usr_id
AND po_approvals.enq_id IS NOT NULL
FETCH NEXT 5 ROWS ONLY
);

PowerBuilder 12.5 sql cursors transaction size error

i have a major problem and trying to find a workaround. I have an application in PB12.5 that works on both sql and oracle dbs.. (with a lot of data)
and i m using CURSOR at a point,, but the aplications crashes only in sql. Using debuging in PB i found that the sql connection returs -1 due to huge transaction size. But i want to fetch row by row my data.. is any work around to fetch data like paging?? i mean lets fetch the first 1000 rows next the other 1000 and so on.. i hope that you understand what i want to achieve (to break the fetch process and so to reduce the transaction size if possible) , here is my code
DECLARE trans_Curs CURSOR FOR
SELECT associate_trans.trans_code
FROM associate_trans
WHERE associate_trans.usage_code = :ggs_vars.usage ORDER BY associate_trans.trans_code ;
OPEN trans_Curs;
FETCH trans_Curs INTO :ll_transId;
DO WHILE sqlca.sqlcode = 0
ll_index += 1
hpb_1.Position = ll_index
if not guo_associates.of_asstrans_updatemaster( ll_transId, ls_error) then
ROLLBACK;
CLOSE trans_Curs;
SetPointer(Arrow!)
MessageBox("Update Process", "Problem with the update process on~r~n" + sqlca.sqlerrtext)
cb_2.Enabled = TRUE
return
end if
FETCH trans_Curs INTO :ll_transId;
LOOP
CLOSE trans_Curs;
Since the structure of your source table s not fully presented, I'll make some assumptions here.
Let's assume that the records include a unique field that can be used as a reference (could be a counter or a timestamp). I'll assume here that the field is a timestamp.
Let's also assume that PB accepts cursors with parameters (not all solutions do; if it does not, there are simple workarounds).
You could modify your cursor to be something like:
[Note: I'm assuming also that the syntax presented here is valid for your environment; if not, adaptations are simple]
DECLARE TopTime TIMESTAMP ;
DECLARE trans_Curs CURSOR FOR
SELECT ots.associate_trans.trans_code
FROM ots.associate_trans
WHERE ots.associate_trans.usage_code = :ggs_vars.usage
AND ots.associate_trans.Timestamp < TopTime
ORDER BY ots.associate_trans.trans_code
LIMIT 1000 ;
:
:
IF (p_Start_Timestamp IS NULL) THEN
TopTime = CURRENT_TIMESTAMP() ;
ELSE
TopTime = p_Start_Timestamp ;
END IF ;
OPEN trans_Curs;
FETCH trans_Curs INTO :ll_transId;
:
:
In the above:
p_Start_Timestamp is a received timestamp parameter which would initially be empty and then will contain the OLDEST timestamp fetched in the previous invocation,
CURRENT_TIMESTAMP() is a function of your environment returning the current timestamp.
This solution will work solely when you need to progress in one direction (i.e. from present to past) and that you are accumulating all the fetched records in an internal buffer in case you need to scroll up again.
Hope this makes things clearer.
First of all thank you FDavidov for your effort, so i managed to do it using dynamic datastore instead of cursor,, so here is my solution in case someone else need this.
String ls_sql, ls_syntax, ls_err
Long ll_row
DataStore lds_info
ls_sql = "SELECT associate_trans.trans_code " &
+ " FROM associate_trans " &
+ " WHERE associate_trans.usage_code = '" + ggs_vars.usage +"' "&
+ " ORDER BY associate_trans.trans_code"
ls_syntax = SQLCA.SyntaxFromSQL( ls_sql, "", ls_err )
IF ls_err <> '' THEN
MessageBox( 'Error...', ls_err )
RETURN
END IF
lds_info = CREATE DataStore
lds_info.Create( ls_syntax, ls_err )
lds_info.SetTransObject( SQLCA )
lds_info.Retrieve( )
DO WHILE sqlca.sqlcode = 0 and ll_row <= ll_count
FOR ll_row = 1 TO ll_count
ll_transId = lds_info.GetItemNumber( ll_row, 'trans_code' )
ll_index += 1
hpb_1.Position = ll_index
do while yield(); loop
if not guo_associates.of_asstrans_updatemaster( ll_transId, ls_error) then
ROLLBACK;
DESTROY lds_info
SetPointer(Arrow!)
MessageBox("Update Process", "Problem with the update process on~r~n" + sqlca.sqlerrtext)
cb_2.Enabled = TRUE
return
end if
NEXT
DESTROY lds_info
LOOP

Oracle Statement Ignored error

i've been stuck with this error for a while, could you help me with this?
This's the code i'm trying to run:
CREATE OR REPLACE TRIGGER set_gal_trig
BEFORE INSERT ON MEDIA_CONTENUTI
FOR EACH ROW
DECLARE
tipo_coll VARCHAR2(15);
user2 VARCHAR2(30);
user1 VARCHAR2(30);
BEGIN
SELECT C.Tipo INTO tipo_coll FROM Collezione C WHERE :new.Cod_Collezione = C.Cod_Collezione;
SELECT C.Nome_Utente INTO user1 FROM Collezione C WHERE :new.Cod_Collezione = C.Cod_Collezione;
SELECT M.Nome_Utente INTO user2 FROM Media M WHERE :new.Cod_Media = M.Cod_Media;
IF (tipo = 'SET' AND user1 <> user2)
THEN
Raise_application_error(-20075, 'Inserimento non valido, un SET puo contenere solo media appartenenti al proprietario');
ELSIF (tipo = 'GALLERIA' AND user1= user2)
THEN
Raise_application_error(-20076, 'Inserimento non valido, una GALLERIA puo contenere solo media non appartenenti al proprietario');
END IF;
END;
The error is: Error at line 9: PL/SQL: Statement ignored. Thanks for the help!
Without the full error stack, the obvious error is in line 9 as the top-level error message says (where line numbers are counted only within the PL/SQL part of the statement, not the first three non-PL/SQL lines):
IF (tipo = 'SET' AND user1 <> user2)
You don't have a variable called tipo, so this should be:
IF (tipo_coll = 'SET' AND user1 <> user2)
...
ELSIF (tipo_coll = 'GALLERIA' AND user1= user2)

ORA-22275 error: invalid LOB locator specified

I have a procedure that populates a BLOB variable with a PDF document. What I am trying to do is add logic to only display the PDF document within a 60 day period from a static date. See below:
check_staticdate number(1);
function DisplayPDF (audit in number) RETURN blob is
person_id person.person_id%type;
z_lob blob;
blob_length NUMBER;
CURSOR getPDF(audit number) IS
select report
from report_table
where report_type = 'PDF'
and job_no = audit order by rec_no;
begin
/* Check Valid ID */
if not package.ValidID(person_id, check_only=>TRUE) then
return z_lob;
end if;
/* Here is the case statement.*/
select case
when exists
(
SELECT 'x' from table
where table_id = person_id
and trunc(sysdate) < trunc(table_static_date + 60)
)
then 1
else 0
end into check_staticdate
from dual;
if (check_staticdate = 0) then
return z_lob;
end if;
open getPDF(audit);
fetch getPDF into z_lob;
close getPDF;
return z_lob;
end DisplayPDF;
The error I am receiving is: ORA-22275: invalid LOB locator specified.
I am new to Oracle SQL, and am unsure why my ValidID check works by returning z_lob but my case statement does not.
Edit: Adding full error stack
Failed to execute target procedure ORA-22275: invalid LOB locator specified
ORA-06512: at "SYS.WPG_DOCLOAD", line 51
ORA-06512: at "User.Package", line 733
ORA-06512: at line 33
Initialise your lob with temporary first
DBMS_LOB.CREATETEMPORARY(z_lob,true); --true if you want it to be cached.
Your function is probably returning (depending on your audit parameter value) a blob with a NULL value to the SYS.WPG_DOCLOAD method which throws the unhandled exception you see.
Perhaps you could modify your return z_lob; to be return nvl(z_lob, empty_blob());

Intermittent column does not belong to table exception

I have a stored procedure that gets called hundreds of times per minute. Every once in a rare while I will get an exception that a column does not exist in the query. Here is the exception:
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentException: Column 'SubjectID' does not belong to table .
[ArgumentException: Column 'SubjectID' does not belong to table .]
System.Data.DataRow.GetDataColumn(String columnName) +1775157
System.Data.DataRow.get_Item(String columnName) +13
System.Data.DataTableReader.get_Item(String name) +66
Here is the C# that calls the stored proc:
DataTableReader dtr;
dtr = Util.getDepartmentsByTerm(term);
ddlSubject.Items.Add(new ListItem("Select A Subject...", ""));
while (dtr.Read())
{
//The following line throws the exception!
var value = (string)dtr["SubjectID"];
var text = (string)dtr["title"];
var count = (int) dtr["Count"];
//if (!text.Contains("(0)"))
if(count > 0)
ddlSubject.Items.Add(new ListItem(text, value));
}
Pretty simple... here's the stored procedure:
ALTER PROCEDURE [dbo].[selectDepartmentsByTerm]
(
#term nvarchar(50),
#version int
)
AS
SELECT SubjectID, Subject as Title,(select count(distinct courseno)
from RegistrationBlock WITH (NOLOCK)
where RegistrationBlock.Subject = Subjects.SubjectID
and RegistrationBlock.version = #version
and (#term = '' OR RegistrationBlock.term = #term)) as "Count"
FROM Subjects WITH (NOLOCK)
where Version = #version
order by subject
GO
Tom H.'s comment on my question solved this:
I've seen a post that said that this problem can be caused by a corruption in the connection pool. Make sure that your connections are all being closed properly. You can read some more ways to diagnose/fix the problem here: http://www.ksvali.com/2010/08/solution-to-random-error-column-does-not-belong-to-table/